Gowdy solver
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
sys/mpiWorld.h File Reference

The MPI implementation that splits a grid among the ranks. More...

#include <mpi.h>
Include dependency graph for mpiWorld.h:

Go to the source code of this file.

Data Structures

class  MPIWorld
 Implements the message passing interface (MPI) for high-performance computing (HPC). More...

Functions

int MPIWorld_sanityCheck (int argc, char **argv)
 A sanity check test-bed with benchmarking.

Detailed Description

The MPI implementation that splits a grid among the ranks.

Author:
Mikica Kocic

Definition in file mpiWorld.h.


Function Documentation

int MPIWorld_sanityCheck ( int  argc,
char **  argv 
)

A sanity check test-bed with benchmarking.

To test, replace main by MPIWorld_sanityCheck then invoke mpiexec -n 4 bim-solver 10 10 10 1.

Definition at line 155 of file mpiWorld.h.

References MPIWorld::exchangeBoundaries(), MPIWorld::rank(), MPIWorld::size(), and MPIWorld::waitExchange().

{
    const Int  nGhost = argc >= 2 ? atol ( argv[1] ) : 1;
    const Int  mLen   = argc >= 3 ? atol ( argv[2] ) : 1;
    const Int  nTotal = argc >= 4 ? atol ( argv[2] ) : 80000;
    const bool debug  = argc >= 5;

    MPIWorld mpi;

    Int   nLen        = nTotal / mpi.size(); // nLen should be a multiple of mpi.size()
    Real* gridRow     = new Real[ nLen + 2 * nGhost ];
    Real* myData      = gridRow + nGhost;
    Real* left_ghost  = gridRow;
    Real* left_edge   = gridRow + nGhost;
    Real* right_edge  = gridRow + nGhost + nLen - nGhost;
    Real* right_ghost = gridRow + nGhost + nLen;

    for ( Int m = 0; m <  mLen; ++m )
    {
        left_ghost  [0] = -1;
        left_edge   [0] = ( mpi.rank () + 1 ) * 1000 + m * 100 + 1;
        myData      [0] = ( mpi.rank () + 1 ) * 1000 + m * 100 + 2;
        right_edge  [0] = ( mpi.rank () + 1 ) * 1000 + m * 100 + 3;
        right_ghost [0] = -1;

        if ( debug ) {
            std::printf( "PRE %*s %5.0lf|%5.0lf%5.0lf%5.0lf|%5.0lf\n", mpi.rank() * 16,
                "", *left_ghost, *left_edge, *myData, *right_edge, *right_ghost );
        }

        mpi.exchangeBoundaries(
            left_ghost, left_edge, right_edge, right_ghost, nGhost );

        // Do a sample calculation (equally divided among the ranks)
        // The calculation depends on the left ghost.
        for ( Int n = nGhost; n < nGhost + nLen; ++n ) {
            gridRow[n] = gridRow[n-1] + cos(n) * exp( n * sin(n) );
        }

        mpi.waitExchange ();

        if ( debug ) {
            printf( "POST%*s %5.0lf|%5.0lf%5.0lf%5.0lf|%5.0lf\n", mpi.rank() * 16,
                   "", *left_ghost, *left_edge, *myData, *right_edge, *right_ghost );
        }
    }

    return 0;
}