Comparing the performance of MPI vector datatypes

 

Performance of MPI vector datatypes

 

 

1. write a program to send a vector of 1000 elements of type MPI_DOUBLE, with a stride of 24 between each element. You may want to use these MPI routines in your solution:
2. Time routines and do several interations to get a good average and repeat the test 10 times.

Use the following example and complete the arguments of the calling routines for MPI_Type_vector 
#include < stdio.h>
#include < stdlib.h>
#include "mpi.h"

#define NUMBER_OF_TESTS 10

int main( argc, argv )
int argc;
char **argv;
{
    MPI_Datatype vec1, vec_n;
    int          blocklens[2];
    MPI_Datatype old_types[2];

    double       *buf, *lbuf;
    register double *in_p, *out_p;
    int          rank;
    int          n, stride;
    double       t1, t2, tmin;
    int          i, j, k, nloop;
    MPI_Status   status;

    MPI_Init( &argc, &argv );

    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    n      = 1000;
    stride = 24;
    nloop  = 100000/n;

    buf = (double *) malloc( n * stride * sizeof(double) );
    if (!buf) {
        fprintf( stderr, "Could not allocate send/recv buffer of size %d
",
                 n * stride );
        MPI_Abort( MPI_COMM_WORLD, 1 );
    }
    lbuf = (double *) malloc( n * sizeof(double) );
    if (!lbuf) {
        fprintf( stderr, "Could not allocated send/recv lbuffer of size %d
",
                 n );
        MPI_Abort( MPI_COMM_WORLD, 1 );
    }

    if (rank == 0) 
        printf( "Kind	n	stride	time (sec)	Rate (MB/sec)
" );

    /* Use a fixed vector type */
    MPI_Type_vector( ******************************* );
    MPI_Type_commit( ***** );

    tmin = 1000;
    for (k=0; k < NUMBER_OF_TESTS; k++) {
        if (rank == 0) {
            t1 = MPI_Wtime();
            for (j=0; j < nloop; j++) {
                MPI_Send(*********************************** );
                MPI_Recv( ******************************************* );
            }
            t2 = (MPI_Wtime() - t1) / nloop;
            if (t2 < tmin) tmin = t2;
        }
        else if (rank == 1) {
            for (j=0; j < nloop; j++) {
                MPI_Recv( buf, 1, vec1, 0, k, MPI_COMM_WORLD, &status );
                MPI_Send( buf, 1, vec1, 0, k, MPI_COMM_WORLD );
            }
        }
    }
    /* Convert to half the round-trip time */
    tmin = tmin / 2.0;
    if (rank == 0) {
        printf( "Vector	%d	%d	%f	%f
", 
                n, stride, tmin, n * sizeof(double) * 1.0e-6 / tmin );
    }
    MPI_Type_free( &vec1 );


    MPI_Finalize( );
    return 0;
}