This document discusses 4 commonly used MPI functions - MPI_Init, MPI_Comm_Rank, MPI_Comm_Size, and MPI_Finalize. It provides a C code example that uses these functions to print "Hello world from process # of #" and a similar Fortran code example.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
32 views
Hello World MPI Examples
This document discusses 4 commonly used MPI functions - MPI_Init, MPI_Comm_Rank, MPI_Comm_Size, and MPI_Finalize. It provides a C code example that uses these functions to print "Hello world from process # of #" and a similar Fortran code example.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
Hello World MPI Examples
4 most used MPI functions/subroutines
MPI_Init MPI_Comm_Rank MPI_Comm_Size MPI_Finalize /* C Example */ #include <stdio.h> #include <mpi.h>
int main (argc, argv) 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; }
c Fortran example program hello include 'mpif.h' integer rank, size, ierror, tag, status(MPI_STATUS_SIZE)