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 8055001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:16:17+00:00 2026-06-05T08:16:17+00:00

I have a problem with the following code: #include mpi.h #include <stdio.h> #include <stdlib.h>

  • 0

I have a problem with the following code:

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

#define NUM_SPAWNS 2
// Based on the example from: http://mpi.deino.net/mpi_functions/MPI_Comm_spawn.html
void MPI_messenger(int stuff, int dest)
{
    MPI_Send(&stuff, 1, MPI_INT, dest, 1,intercomm);
}

int main( int argc, char *argv[] )
{
    int my_rank;
    int size;
    int np = NUM_SPAWNS;
    int errcodes[NUM_SPAWNS];
    MPI_Comm parentcomm, intercomm, testcomm;
    MPI_Init( &argc, &argv );
    MPI_Status stat;
    MPI_Comm_get_parent( &parentcomm );
    if (parentcomm == MPI_COMM_NULL)
    {
        MPI_Comm_spawn( "spawn_example4", MPI_ARGV_NULL, np, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm, errcodes );
        MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
        MPI_Comm_size(MPI_COMM_WORLD, &size);
        int lol = 10;
        MPI_messenger(lol,0);
        MPI_messenger(lol,1);
    }
    else
    {
        MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
        MPI_Comm_size(MPI_COMM_WORLD, &size);
        int lol;
        MPI_Recv(&lol, 1, MPI_INT,0,1,parentcomm, &stat);


        std::cout << lol << "\n";
    }
    fflush(stdout);
    MPI_Finalize();
    return 0;
}

Of course the intercommunicator intercomm is not defined in the scope of the function MPI_messenger. I wanted to know if and how I can get this intercommunicator inside the function without passing it as an argument.

  • 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-05T08:16:18+00:00Added an answer on June 5, 2026 at 8:16 am

    The same way you would any other variable: declare it globally, or in some other common scope visible to both main() and MPI_messenger() (e.g. within the same class as a member).

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

Sidebar

Related Questions

The problem I have is illustrated in the following code. #include <iostream> #define X
I have a problem with the following code: #include <stdio.h> #include <iostream> int main
I have the following code: #include <iostream> #include Student.h <-- fixed the problem #include
I have a problem with the following code #include <stdio.h> int main() /* Tidsberäkning
I have a problem with the following code: #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <iostream>
I have a problem compiling the following code: #include <stdio.h> #include <limits.h> int main
I have slimmed my problem down to the following code: #include <iostream> using namespace
i have following code in c++ #include <iostream> using namespace std; void qsort5(int a[],int
I have following code: #include <iostream> using namespace std; template<class T> T max(T *data,int
i have the following main code: #include ComHandler.h #include socketMessage.h #define THIS_IP localhost #define

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.