Skip to content

Instantly share code, notes, and snippets.

@Ari-Roda
Last active January 24, 2018 04:49
Show Gist options
  • Save Ari-Roda/4537dc6c3465d09dee669059a7a92e3e to your computer and use it in GitHub Desktop.
Save Ari-Roda/4537dc6c3465d09dee669059a7a92e3e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "mpi.h"
int main(int argc, char *argv[])
{
int r, myid, procs, ierr, i;
struct timeval tv;
int myval, val, tval;
MPI_Status status;
FILE *fp;
char s[64];
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
r = rand();
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
MPI_Comm_size(MPI_COMM_WORLD, &procs);
if (myid == 0){
printf("%d : %d\n", myid, r);
for (i = 1; i < procs; i++){
MPI_Recv(&val, 1, MPI_INT, i, 0, MPI_COMM_WORLD,&status);
printf("%d : %d\n", i, val);
}
fclose(fp);
} else
MPI_Send(&r, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
MPI_Finalize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment