NSSC/Exercise_01/examples/MPI_hello_world.cpp

36 lines
909 B
C++
Raw Normal View History

2022-03-11 09:26:56 +00:00
/**
* Compile
* mpic++ MPI_hello_world.cpp -std=c++17 -Wall -pedantic -Wpedantic
* Usage
* mpirun -n 4 ./a.out
*
* Note: An easy way to finde the location of the `mpi.h` file is
* mpic++ --showme:compile
* which might be usefull to configure the intelicense.
*/
#include <iostream>
#include <mpi.h>
int main(int argn, char* argv[]) {
// Initialize MPI (always required)
MPI_Init(nullptr, nullptr);
// Allocate MPI Settings
int num_proc; /*< Number of processes */
int rank; /*< This process rank (a.k.a. the MPI process ID) */
// Set/Get MPI Settings
MPI_Comm_size(MPI_COMM_WORLD, &num_proc);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// Write MPI info to stdout
std::cout << "Hello World, i am rank " << rank << " of " << num_proc
<< " processes." << std::endl;
// Shutdown MPI (always required)
MPI_Finalize();
return 0;
}