Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mpi.h>
- #include <stdio.h>
- #include <math.h>
- #define N 10000
- #define MAX 1000
- int main(int argc,char* argv[]){
- int i,np,yo,warn,flag;
- double n;
- srand (time(NULL));
- MPI_Init(&argc,&argv);
- MPI_Comm_size(MPI_COMM_WORLD,&np);
- MPI_Comm_rank(MPI_COMM_WORLD,&yo);
- double vectorRandom[np];
- MPI_Request req;
- MPI_Status status;
- if(yo==0){
- warn = 13;
- n = rand() % N;
- for(i=0;i<MAX;i++) n = rand() % N;
- // Avisar a demás procesos //
- for(i=0;i<np;i++) MPI_Send(&warn,1,MPI_INT,i,0,MPI_COMM_WORLD);
- }
- else{
- n = rand() % N;
- flag = 0;
- // Recepción no bloqueante //
- MPI_Irecv(&warn,1,MPI_INT,0,0,MPI_COMM_WORLD,&req);
- MPI_Test(&req,&flag,&status);
- while(!flag){
- n = rand() % N ;
- MPI_Test(&req,&flag,&status);
- }
- }
- // Recogida en proceso 0 //
- MPI_Gather(&n,1,MPI_DOUBLE,vectorRandom,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
- if(yo==0){
- int f = rand() % np;
- printf("Random: %f,",vectorRandom[f]);
- }
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement