i'm tring to make each process to send random value to two random destination ,destination1 and destination2 .each process print what send and receive.
this is code:
#include "mpi.h"
#include "head.h"
#include<iostream>
#include <random>
#include <vector>
#include <time.h>
int main(int argc, char *argv[])
{
int my_rank,rc,destination1,destination2,numpros,count=0,tag;
rc = MPI_Init(&argc,&argv);
if (rc != MPI_SUCCESS)
{
printf ("Error starting MPI program. Terminating.\n");
MPI_Abort(MPI_COMM_WORLD, rc);
}
MPI_Comm_size(MPI_COMM_WORLD,&numpros);
MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
MPI_Status status;
MPI_Request reqs;
double buffer=rand() % 6;
do {
destination1=rand() % numpros;
destination2=rand() % numpros;
} while ((destination1 == my_rank) && (destination2==my_rank)&&(destination1!=destination2)); //Prevent sending to self
MPI_Isend(&buffer,1,MPI_INT,destination1,tag,MPI_COMM_WORLD,&reqs);
MPI_Isend(&buffer,1,MPI_INT,destination2,tag,MPI_COMM_WORLD,&reqs);
count++;
vector<head*>array_data;
for(int i ;i<count,i++){
array_data[i]=new head;
array_data[i]->rank=my_rank;
array_data[i]->rank1=destination1;
array_data[i]->rank2=destination2;
}
MPI_Bcast(&array_data,array_data.size(),MPI_INT,my_rank,MPI_COMM_WORLD);
for(int j=0,j<array_data.size();j++){
if(array_data[j].rand1==my_rank||array_data[j].rand2==my_rank)
source=array_data[j].rank;
MPI_Recv(&buffer,1,MPI_INT,source,MPI_ANY_TAG,MPI_COMM_WORLD,&status);
}
MPI_Waitall(numprocs, reqs, status);
printf("process :%d \t\n sent %d to %d\t\n to %d \n",my_rank,buffer,destination1,destination2);
printf("process %d recived %d from %d\n",source,buffer,my_rank);
MPI_Finalize();
}
elements of stuct are:
stuct head {
int rank;
int rand1;
int rand2;
};
every time i execute program show this error: anysome can help me ?
Aucun commentaire:
Enregistrer un commentaire