Skip to content

Instantly share code, notes, and snippets.

@understeer
Created March 10, 2014 10:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save understeer/9462697 to your computer and use it in GitHub Desktop.
Save understeer/9462697 to your computer and use it in GitHub Desktop.
OpenMPI test sample
/*
* Usage:
* mpicc mpitest.c -o mpitest
* mpirun -np 2 -H `hostname` ./mpitest
*/
#include <stdio.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
int rank, size, h_len;
char hostname[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc, &argv);
// get rank of this proces
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// get total process number
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Get_processor_name(hostname, &h_len);
printf("Start! rank:%d size: %d at %s\n", rank, size,hostname);
//do something
printf("Done! rank:%d size: %d at %s\n", rank, size,hostname);
MPI_Finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment