Debugging 如何修复此MPI代码程序
这个程序演示了一个不安全的程序,因为有时它执行得很好,有时它会失败。程序失败或挂起的原因是由于接收任务端的缓冲区耗尽,这是MPI库为特定大小的消息实现渴望协议的结果。一种可能的解决方案是在发送和接收循环中都包含MPI_屏障调用 它的程序代码如何正确Debugging 如何修复此MPI代码程序,debugging,mpi,Debugging,Mpi,这个程序演示了一个不安全的程序,因为有时它执行得很好,有时它会失败。程序失败或挂起的原因是由于接收任务端的缓冲区耗尽,这是MPI库为特定大小的消息实现渴望协议的结果。一种可能的解决方案是在发送和接收循环中都包含MPI_屏障调用 它的程序代码如何正确 #include "mpi.h" #include <stdio.h> #include <stdlib.h> #define MSGSIZE 2000 int main (int argc, char *argv[])
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#define MSGSIZE 2000
int main (int argc, char *argv[])
{
int numtasks, rank, i, tag=111, dest=1, source=0, count=0;
char data[MSGSIZE];
double start, end, result;
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
printf ("mpi_bug5 has started...\n");
if (numtasks > 2)
printf("INFO: Number of tasks= %d. Only using 2 tasks.\n", numtasks);
}
/******************************* Send task **********************************/
if (rank == 0) {
/* Initialize send data */
for(i=0; i<MSGSIZE; i++)
data[i] = 'x';
start = MPI_Wtime();
while (1) {
MPI_Send(data, MSGSIZE, MPI_BYTE, dest, tag, MPI_COMM_WORLD);
count++;
if (count % 10 == 0) {
end = MPI_Wtime();
printf("Count= %d Time= %f sec.\n", count, end-start);
start = MPI_Wtime();
}
}
}
/****************************** Receive task ********************************/
if (rank == 1) {
while (1) {
MPI_Recv(data, MSGSIZE, MPI_BYTE, source, tag, MPI_COMM_WORLD, &status);
/* Do some work - at least more than the send task */
result = 0.0;
for (i=0; i < 1000000; i++)
result = result + (double)random();
}
}
MPI_Finalize();
}
#包括“mpi.h”
#包括
#包括
#定义msgsize2000
int main(int argc,char*argv[])
{
int numtasks,rank,i,tag=111,dest=1,source=0,count=0;
字符数据[MSGSIZE];
双重开始、双重结束、双重结果;
MPI_状态;
MPI_Init(&argc,&argv);
MPI通信大小(MPI通信世界和numtasks);
MPI通信等级(MPI通信世界和等级);
如果(秩==0){
printf(“mpi_bug5已启动…\n”);
如果(numtasks>2)
printf(“信息:任务数=%d。仅使用2个任务。\n”,numtask);
}
/*******************************发送任务**********************************/
如果(秩==0){
/*初始化发送数据*/
对于(i=0;i改进此代码的方法,以便接收器不会以无限数量的包含结束:
- 同步-您提到了MPI_屏障,但即使使用MPI_Ssend而不是MPI_Send也可以
- 显式缓冲-使用MPI_Bsend或Brecv确保存在足够的缓冲
- Posted receives—接收流程在开始工作之前发布IRECV,以确保将消息接收到用于保存数据的缓冲区中,而不是系统缓冲区中
在这个教学案例中,由于消息的数量是无限的,只有第一个(同步)可以可靠地工作。请正确格式化您的代码,请参阅。谢谢您,先生..您能告诉我它的程序代码行是正确的吗..请帮助我!谢谢您