mpi运行

1
2
brew install openmpi
export OMPI_CXX=g++-7
1
2
mpic++ helloworld.cpp -o helloworld.out
mpirun -n 2 ./helloworld.out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <cstdio>
#include <mpi.h>

int main (int argc, char **argv)
{
int rank, size;

MPI_Init (&argc, &argv); /* starts MPI */

MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */
MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */

printf( "Hello world from process %d of %d\n", rank, size );

MPI_Finalize();

return 0;
}
请作者喝一杯咖啡☕️