Noor
Noor

Reputation: 20178

How can i declare MPI_COMM_WORLD so that I can use it everywhere?

You can notice that the code is instantiated in MPI_COMM_WORLD but is being used in function send_code!

my codes are:

int send_code(char *code)
{
        //produce the codes for adding the code into the table
        printf("%s\n",code);
        MPI_Send(code, 8, MPI_CHAR,0, 0,MPI_COMM_WORLD);
}

int main(int argc, char *argv[])
{

        MPI_Status status;
        int outbuf, inbuf;

        MPI_Init(&argc, &argv);
        MPI_Comm_size(MPI_COMM_WORLD, &size);
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
        if (rank==0)
        {
               MPI_Recv(code, 8, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);
               printf("%s by master\n",code);

        }
        else
        {
                ........
        }

        MPI_Finalize();
}

Upvotes: 0

Views: 3281

Answers (2)

Jeremiah Willcock
Jeremiah Willcock

Reputation: 30999

If you are asking about the MPI_COMM_WORLD in MPI, it is declared in mpi.h and defined somewhere in one of the MPI implementation's libraries.

Upvotes: 3

tchap
tchap

Reputation: 1057

Static global variable? If that is safe enough for you and you are ready to bear the risks ;-)

Upvotes: 0

Related Questions