Parallel processing mpi并行程序寻找素数。请帮帮我

Parallel processing mpi并行程序寻找素数。请帮帮我,parallel-processing,numbers,mpi,Parallel Processing,Numbers,Mpi,我编写了以下程序来查找具有#定义值的素数。它是使用mpi的并行程序。有人能帮我找出其中的错误吗。它编译得很好,但在执行时崩溃 #include <stdio.h> #include <stdlib.h> #include <mpi.h> #define N 65 int rank, size; double start_time; double end_time; int y, x, i, port1, port2, port3; int check =0

我编写了以下程序来查找具有#定义值的素数。它是使用mpi的并行程序。有人能帮我找出其中的错误吗。它编译得很好,但在执行时崩溃

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#define N 65

int rank, size;
double start_time;
double end_time;

int y, x, i, port1, port2, port3;
int check =0;         // prime number checker, if a number is prime it always remains 0      through out calculation. for a number which is not prime it is turns to value 1 at some    point
int signal =0;       // has no important use. just to check if slave process work is done.

MPI_Status status;
MPI_Request request;

int main(int argc, char *argv[]){
MPI_Init(&argc, &argv); //initialize MPI operations
MPI_Comm_rank(MPI_COMM_WORLD, &rank); //get the rank
MPI_Comm_size(MPI_COMM_WORLD, &size); //get number of processes

if(rank == 0){                  // master process divides work and also does initial  work itself
start_time = MPI_Wtime();
printf("2\n");                  //print prime number 2 first  because the algorithm for finding the prime number in this program is just for odd number
port1 = (N/(size-1));           // calculating the suitable amount of work per process

for(i=1;i<size-1;i++){            // master sending the portion of work to each   slave
port2 = port1 * i;              // lower bound of work for i th  process 
port3 = ((i+1)*port1)-1;        // upper bound of work for i th process
MPI_Isend(&port2, 1, MPI_INT, i, 100, MPI_COMM_WORLD, &request);
MPI_Isend(&port3, 1, MPI_INT, i, 101, MPI_COMM_WORLD, &request);
}

port2 = (size-1)*port1; port3= N;     // the last process takes the remaining work
MPI_Isend(&port2, 1, MPI_INT, (size-1), 100, MPI_COMM_WORLD, &request);
MPI_Isend(&port3, 1, MPI_INT, (size-1), 101, MPI_COMM_WORLD, &request);

for(x = 3; x < port1; x=x+2){    // master doing initial work by itself
check = 0;
for(y = 3; y <= x/2; y=y+2){
if(x%y == 0) {check =1; break;}
}
if(check==0) printf("%d\n", x);
}
}

if (rank > 0){                    // slave working part

MPI_Recv(&port2,1,MPI_INT, 0, 100, MPI_COMM_WORLD, &status);
MPI_Recv(&port3,1,MPI_INT, 0, 101, MPI_COMM_WORLD, &status);
if (port2%2 == 0) port2++;                                        // changing the even  argument to odd to make the calculation fast because even number is never a prime except 2.
for(x=port2; x<=port3; x=x+2){
check = 0;
for(y = 3; y <= x/2; y=y+2){
if(x%y == 0) {check =1; break;}
}
    if (check==0) printf("%d\n",x);
}
signal= rank;
MPI_Isend(&signal, 1, MPI_INT, 0, 103, MPI_COMM_WORLD, &request);  // just informing  master that the work is finished

}

if (rank == 0){                                                    // master concluding the work and printing the time taken to do the work
for(i== 1; i < size; i++){
MPI_Recv(&signal,1,MPI_INT, i, 103, MPI_COMM_WORLD, &status);  // master confirming that all slaves finished their work
}
end_time = MPI_Wtime();
printf("\nRunning Time = %f \n\n", end_time - start_time);
   }
   MPI_Finalize();
   return 0;
   } 
#包括
#包括
#包括
#定义N 65
int等级、大小;
双启动时间;
双端时间;
输入y、x、i、端口1、端口2、端口3;
int check=0;//素数检查器,如果一个数是素数,它在整个计算过程中始终保持为0。对于一个非素数的数,它在某一点上变成了值1
int信号=0;//没有什么重要用途。只是为了检查从进程工作是否完成。
MPI_状态;
MPI_请求;
int main(int argc,char*argv[]){
MPI_Init(&argc,&argv);//初始化MPI操作
MPI_Comm_rank(MPI_Comm_WORLD,&rank);//获取排名
MPI_Comm_size(MPI_Comm_WORLD,&size);//获取进程数
如果(秩==0){//主进程分配工作,并且自己也做初始工作
开始时间=MPI时间();
printf(“2\n”);//首先打印素数2,因为此程序中查找素数的算法仅适用于奇数
port1=(N/(size-1));//计算每个进程的适当工作量

对于(i=1;i我发现我的程序有什么问题。
这是使用了受限变量信号。将该变量的名称(在使用该变量的所有位置)更改为任何其他可行的名称,它就会工作。

您需要正确格式化代码,使其可读。