Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created April 10, 2017 00:43
Show Gist options
  • Save kaityo256/096f59a6fcdf287fda7e0d28ebd22746 to your computer and use it in GitHub Desktop.
Save kaityo256/096f59a6fcdf287fda7e0d28ebd22746 to your computer and use it in GitHub Desktop.
MPI sample
#include <stdio.h>
#include <mpi.h>
int
main(int argc, char **argv) {
int rank = 0;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (0 == rank) {
int send_value = 12345;
MPI_Send(&send_value, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
} else {
class Hoge {
private:
int private_value;
public:
void recv() {
MPI_Status st;
MPI_Recv(&private_value, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &st);
}
void show() {
printf("my private value is %d\n", private_value);
}
};
Hoge h;
h.recv();
h.show();
}
MPI_Finalize();
}
@kaityo256
Copy link
Author

$ mpic++ test.cpp
$ mpirun -np 2 ./a.out 
my private value is 12345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment