| 1 | = MPI C++ = |
| 2 | == Hello World == |
| 3 | {{{#!cpp |
| 4 | // |
| 5 | // hello_mpi.cpp: display a message on the screen |
| 6 | // |
| 7 | #include <iostream> |
| 8 | #include <mpi.h> |
| 9 | |
| 10 | int main (int argc, char *argv[]) { |
| 11 | // Initialize |
| 12 | MPI::Init(argc, argv); |
| 13 | |
| 14 | // get myid and # of processors |
| 15 | int numproc = MPI::COMM_WORLD.Get_size(); |
| 16 | int myid = MPI::COMM_WORLD.Get_rank(); |
| 17 | |
| 18 | std::cout << "hello from " << myid << std::endl; |
| 19 | |
| 20 | // wait until all processors come here |
| 21 | MPI::COMM_WORLD.Barrier(); |
| 22 | |
| 23 | if ( myid == 0 ) { |
| 24 | // only myid = 0 do this |
| 25 | std::cout << numproc << " processors said hello!" << std::endl; |
| 26 | } |
| 27 | |
| 28 | MPI::Finalize(); |
| 29 | } |
| 30 | }}} |
| 31 | == Compile == |
| 32 | {{{mpiCC hello_mpi.cpp}}} |
| 33 | == Example of Jobscript == |
| 34 | [[https://wiki.hpc.tulane.edu/trac/wiki/cypress/Programming/Cexamples#ExamplesofJobscript|See Example]] |