/**************************************************************************** * FILE: datatypes.c * DESCRIPTION: * This code compares timings of MPI non-contiguous derived datatypes * against sending the same data without using derived datatypes. The * comparisons all send a vector of 1000 elements of type MPI_DOUBLE, with a * stride of 24 between each element. The four tests use: * 1. MPI_Type_vector * 2. MPI_Type_struct * 3. Hand packing and unpacking of the strided vector to/from a contiguous * vector * 4. Individual send/recv for each strided element of the vector * * Cases 1 and 2 use MPI non-contiguous derived datatypes, cases 3 and 4 do * not. Case 3 demonstrates how to improve on the MPI non-contiguous derived * datatypes, while case 4 demonstrates a worst case method of sending * strided data elements. * * SOURCE: Adapted from example code provided with the "Performance Tuning * MPI" tutorial materials by William Gropp and Ewing Lusk, located at * www.mcs.anl.gov/mpi/tutorial * LAST REVISED: 01/09/99 Blaise Barney ******************************************************************************/ #include #include #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_Aint indices[2]; MPI_Datatype old_types[2]; double *buf, *lbuf, t1, t2, tmin; int rank, n, stride, 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", n * stride ); MPI_Abort( MPI_COMM_WORLD, 1 ); } lbuf = (double *) malloc( n * sizeof(double) ); if (!lbuf) { fprintf( stderr, "Could not allocate send/recv lbuffer of size %d\n", n ); MPI_Abort( MPI_COMM_WORLD, 1 ); } if (rank == 0) printf( "Kind\tn\tstride\ttime (sec)\tRate (MB/sec)\n" ); /*************************** Test 1 ************************************/ /* Use a fixed vector type */ MPI_Type_vector( n, 1, stride, MPI_DOUBLE, &vec1 ); MPI_Type_commit( &vec1 ); tmin = 1000; for (k=0; k