Last active
January 24, 2018 04:49
-
-
Save Ari-Roda/4537dc6c3465d09dee669059a7a92e3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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