TRIQS/mpi 1.3.0
C++ interface to MPI
Loading...
Searching...
No Matches
Example 1: Hello world!

In this example, we show how to implement the standard Hello world program using mpi.

#include <mpi/mpi.hpp>
#include <iostream>
int main(int argc, char *argv[]) {
// initialize MPI environment and communicator
mpi::environment env(argc, argv);
// get rank and greet world
int rank = world.rank();
std::cout << "Hello from processor " << rank << "\n";
}
C++ wrapper around MPI_Comm providing various convenience functions.
int rank() const
Get the rank of the calling process in the communicator.
Includes all relevant mpi headers.
RAII class to initialize and finalize MPI.

Output (depends on the number of processes and the order is arbitrary):

Hello from processor 2
Hello from processor 3
Hello from processor 0
Hello from processor 1