Skip to content

Instantly share code, notes, and snippets.

@axper
Created December 26, 2014 18:17
Show Gist options
  • Save axper/72781d426ad31e41f513 to your computer and use it in GitHub Desktop.
Save axper/72781d426ad31e41f513 to your computer and use it in GitHub Desktop.
mpi sample code
#include <mpi.h>
#include <stdio.h>
void errhandler_function(MPI_Comm * communicatior, int * error_code, ...) {
printf("ERROR HANDLED: %d", *error_code);
MPI_Abort(*communicatior, *error_code);
}
int main(int argc, char** argv)
{
const int maximum_message_length = 100;
const int master_rank = 0;
char message[maximum_message_length + 1];
MPI_Status status;
int my_rank;
int num_procs;
int source;
int destination;
int tag = 0;
int mpi_error;
MPI_Errhandler errhandler;
MPI_Init(&argc, &argv);
MPI_Comm_create_errhandler(errhandler_function, &errhandler);
MPI_Comm_set_errhandler(MPI_COMM_WORLD, errhandler);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
if (my_rank == master_rank) {
printf("Hello i am master\n");
} else {
printf("Hello i am slave\n");
}
MPI_Finalize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment