Created
December 26, 2014 18:17
-
-
Save axper/72781d426ad31e41f513 to your computer and use it in GitHub Desktop.
mpi sample code
This file contains 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 <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