icp/oer/courses/c-mpi/sections/01-introduction/01-c-hello/program.c

22 lines
536 B
C
Raw Normal View History

2018-05-05 22:18:02 +00:00
#include <stdio.h>
#include <mpi.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int rank;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
srand(2);
int random = rand();
MPI_Send(&random, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
printf("rank 0 random: %d \t", random);
} else if (rank == 1) {
int random;
// Recieve data from rank 0 here:
printf("rank 1, random: %d", random);
}
MPI_Finalize();
}