Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7919645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:56:08+00:00 2026-06-03T15:56:08+00:00

I am taking my first steps in the world of parallel programming with Open

  • 0

I am taking my first steps in the world of parallel programming with Open MPI. What I’m trying to achieve is to start an application with two processes (this can be achieved with mpirun -n 2 …) and make the first process from these both spawn another instance of itself. Here is the sketch in c++:

// mpi_spawn_cpp2.cc
#include "mpi.h"
#include <iostream>

using namespace std;

int main( int argc, char *argv[] )
{
    int rank, size;
    int errcode;
    MPI::Intercomm intercomm;

    MPI::Init( argc, argv );

    rank = MPI::COMM_WORLD.Get_rank();
    size = MPI::COMM_WORLD.Get_size();
    cout << "world size: " << size << endl;

    if (rank == 0) {
        intercomm = MPI::COMM_WORLD.Spawn("./mpi_spawn_cpp2", MPI::ARGV_NULL, 1, MPI::INFO_NULL, 0, &errcode);
        cout << "intercomm size: " << intercomm.Get_size() << endl;
    }

    MPI::Finalize();
    return 0;
}

Although it compiles flawlessly the problem with the above code is that it doesn’t seem to return from the Spawn function, which means the process is in fact not spawned. What is wrong with the above code and what should be corrected in order for it to work?

Your help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:56:09+00:00Added an answer on June 3, 2026 at 3:56 pm

    MPI_Comm_spawn is collective over the intracommunicator but you are calling it only from rank 0 and that’s why it hangs. Try this instead:

    intercomm = MPI::COMM_WORLD.Spawn("./mpi_spawn_cpp2", MPI::ARGV_NULL, 1, MPI::INFO_NULL, 0, &errcode);
    if (rank == 0) {
        cout << "intercomm size: " << intercomm.Get_size() << endl;
    }
    

    A word of advice. Since it is your first steps in MPI, I would recommend that you learn the C bindings instead. The C++ bindings are deprecated in the current MPI standard version 2.2 and will be completely dropped from the upcoming version 3.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am taking my first steps programming in Lua and get this error when
First, I dont have any experience with programming. If I ever start, then this
I am taking first steps in socket programming as an added complexity I am
I am taking my first steps in XML-schema land, using XSD, and I'm trying
I'm taking my first steps through Unity, as a follow up to this question:
I'm taking my first steps in python programming, I have a class named node
I'm taking my first steps in OpenCL programming. I like it very much. But
I am taking my first steps in the world of iPhone/iPad development with MonoTouch
I'm taking my first interesting steps (non-hello-world level) with Scala (2.9.1) and I'm stuck
I'm just taking my first steps with Azure and the first thing I see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.