我正在尝试在超立方体拓扑上使用 mpi c 库计算 pi。但执行不会继续 MPI_Send 和 MPI_Recv 部分。
我正在使用4个处理器!
似乎没有一个处理器正在接收任何数据。
这是我得到的代码、输出和错误。
任何帮助,将不胜感激!谢谢!
代码:在每个处理器初始化和计算本地 mypi 之后。
mypi = h * sum;
printf("Processor %d has local pi = %f", myid, mypi);
//Logic for send and receive!
int k;
for(k = 0; k < log10(numprocs) / log10(2.0); k++){
printf("entering dimension %d \n", dimension);
dimension = k;
if(decimalRank[k] == 1 && k < e){
//if it is a processor that need to send then
int destination = 0;
//find destination processor and send
destination = myid ^ (int)pow(2,dimension);
printf("Processor %d sending to %d in dimension %d the value %f\n", myid, destination, dimension, mypi);
MPI_SEND(&mypi, 1, MPI_DOUBLE, destination, MPI_ANY_TAG, MPI_COMM_WORLD);
printf("Processor %d done sending to %d in dimension %d the value %f\n", myid, destination, dimension, mypi);
}
else{
//Else this processor is supposed to be receiving
pi += mypi;
printf("Processor %d ready to receive in dimension %d\n", myid, dimension);
MPI_RECV(&mypi, 1, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD);
printf("Processor %d received value %d in dimension %d\n", myid, pi, dimension);
pi += mypi;
}
}
done = 1;
}
错误:
mpiexec: Warning: tasks 0-3 died with signal 11 (Segmentation fault).
输出:
bcast complete
Processor 0 has local pi = 0.785473
Processor 0 ready to receive in dimension 0
Processor 1 has local pi = 0.785423
Processor 1 sending to 0 in dimension 0 the value 0.785423
Processor 3 has local pi = 0.785323
Processor 3 sending to 2 in dimension 0 the value 0.785323
Processor 2 has local pi = 0.785373
Processor 2 ready to receive in dimension 0