File: hello.cpp

package info (click to toggle)
mpi-defaults 1.19
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 68 kB
  • sloc: makefile: 112; cpp: 16; ansic: 15; sh: 14; f90: 9; fortran: 9
file content (28 lines) | stat: -rw-r--r-- 783 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <mpi.h>
#include <iostream>

int main(int argc, char** argv) {
    // Initialize the MPI environment
    MPI_Init(NULL, NULL);

    // Get the number of processes
    int world_size;
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);

    // Get the rank of the process
    int world_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

    // Get the name of the processor
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    int name_len;
    MPI_Get_processor_name(processor_name, &name_len);

    // Print off a hello world message
    std::cout << "Hello world from processor " << processor_name
              << ", rank " << world_rank << " out of " << world_size
              << " processors" << std::endl;

    // Finalize the MPI environment.
    MPI_Finalize();
}