Skip to content

Instantly share code, notes, and snippets.

@aprell
Created December 2, 2011 16:05
Show Gist options
  • Save aprell/1423772 to your computer and use it in GitHub Desktop.
Save aprell/1423772 to your computer and use it in GitHub Desktop.
Hello MPI
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#define WORKER(id) if (ID == (id))
#define MASTER WORKER(0)
int main(int argc, char *argv[])
{
int numprocs, ID;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &ID);
MASTER printf("Master %d: Hello MPI!\n", ID);
else printf("Worker %d: Hello MPI!\n", ID);
MPI_Finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment