user5538696
user5538696

Reputation:

MPI with C: Communication time

I have just started learning MPI and this is my first program for sending and receiving data between two processor...

            MPI_Status status;
            MPI_Init(&argc,&argv);
            MPI_Comm_rank(MPI_COMM_WORLD,&rank);
            MPI_Comm_size(MPI_COMM_WORLD,&size);
            printf("Comm Size %d",size);
            printf("Rank %d",rank);
            if (rank == 0)
                    {
                            for(j=1;j<size;j++);
                                    {
                                            tmp = clock();
                                            start_time = clock();
                                            MPI_Send(&N,1,MPI_INT,j,j,MPI_COMM_WORLD);
                                            MPI_Recv(&N,1,MPI_INT,j,j,MPI_COMM_WORLD,&status);
                                            end_time = clock();
                                            timer_overhead = start_time - tmp;
                                            total_time = end_time - start_time - timer_overhead;
                                            communication_time = total_time / 2;
                                            printf("%d",total_time);
                                    }
                    }
            else
                    {
                            MPI_Recv(&N,1,MPI_INT,0,rank,MPI_COMM_WORLD,&status);
                            MPI_Send(&N,1,MPI_INT,0,rank,MPI_COMM_WORLD);
                    }

            MPI_Finalize(); 
    }

~
But this program keep on getting hang, can someone please help.

Upvotes: 1

Views: 446

Answers (1)

Angelos
Angelos

Reputation: 533

At the line where you have the for loop you have put ';' at the end.

for(j=1;j<size;j++);

Remove the ';'.

Upvotes: 3

Related Questions