简体   繁体   English

带C的MPI:通信时间

[英]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,这是我在两个处理器之间发送和接收数据的第一个程序...

            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. 但是这个程序继续挂起,有人可以帮忙。

At the line where you have the for loop you have put ';' 在你有for循环的那一行,你放了';' at the end. 在末尾。

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

Remove the ';'. 去除 ';'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM