यह प्रोग्राम सी लग्रेंज और एमपीआई का उपयोग करके लिखा गया है। मैं एमपीआई के लिए नया हूं और प्रक्रियाओं समेत कुछ गणना करने के लिए सभी प्रोसेसर का उपयोग करना चाहता हूं। इस अवधारणा को जानने के लिए, मैंने निम्नलिखित सरल कार्यक्रम लिखा है। लेकिन इस कार्यक्रम प्रक्रिया 0 से इनपुट प्राप्त करने के बाद निचले भाग में लटकी हुई है और परिणाम प्रक्रिया 0.सभी प्रोसेसर का उपयोग करके एमपीआई में कैसे भेजें/प्राप्त करें
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int number;
int result;
if (world_rank == 0)
{
number = -2;
int i;
for(i = 0; i < 4; i++)
{
MPI_Send(&number, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
}
for(i = 0; i < 4; i++)
{ /*Error: can't get result send by other processos bellow*/
MPI_Recv(&number, 1, MPI_INT, i, 99, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Process 0 received number %d from i:%d\n", number, i);
}
}
/*I want to do this without using an else statement here, so that I can use process 0 to do some calculations as well*/
MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("*Process %d received number %d from process 0\n",world_rank, number);
result = world_rank + 1;
MPI_Send(&result, 1, MPI_INT, 0, 99, MPI_COMM_WORLD); /* problem happens here when trying to send result back to process 0*/
MPI_Finalize();
}
runing और हो रही परिणामों में वापस नहीं भेजेंगे:
:$ mpicc test.c -o test
:$ mpirun -np 4 test
*Process 1 received number -2 from process 0
*Process 2 received number -2 from process 0
*Process 3 received number -2 from process 0
/* hangs here and will not continue */
आप कर सकते हैं, तो , कृपया मुझे उदाहरण के साथ दिखाएं या उपरोक्त कोड को संपादित करें यदि संभव हो।