1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2006 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
6 /* modified 01/23/2011 by Jim Hoekstra - ISU
7 * changed test to follow mtest_init/mtest_finalize convention
8 * The following changes are based on suggestions from Chris Sadlo:
9 * variable row changed to col.
10 * manual transpose - code added to perform 'swap'.
11 * MPI_Send/MPI_Recv involving xpose changed.
14 /* This is based on an example in the MPI standard and a bug report submitted
15 by Alexandr Konovalov of Intel */
24 int main(int argc, char* argv[])
27 static double a[SIZE][SIZE],b[SIZE][SIZE];
28 double t1,t2,t,ts,tst;
30 int myrank, mysize, errs = 0;
34 MPI_Datatype col, xpose;
36 MTest_Init( &argc, &argv );
37 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
38 MPI_Comm_size( MPI_COMM_WORLD, &mysize );
40 fprintf( stderr, "This test must be run with 2 processes\n" );
41 MPI_Abort( MPI_COMM_WORLD, 1 );
44 MPI_Type_extent(MPI_DOUBLE, &sizeofreal);
46 MPI_Type_vector(SIZE, 1, SIZE, MPI_DOUBLE, &col);
47 MPI_Type_hvector(SIZE, 1, sizeofreal, col, &xpose);
48 MPI_Type_commit(&xpose);
50 /* Preset the arrays so that they're in memory */
51 for (i=0; i<SIZE; i++)
52 for (j=0; j<SIZE; j++) {
58 /* Time the transpose example */
59 MPI_Barrier(MPI_COMM_WORLD);
64 MPI_Send(&a[0][0],SIZE*SIZE,MPI_DOUBLE,1,0,MPI_COMM_WORLD);
66 MPI_Recv(&b[0][0],1,xpose,0,0,MPI_COMM_WORLD,&status);
71 /* Time sending the same amount of data, but without the transpose */
72 MPI_Barrier(MPI_COMM_WORLD);
74 for(i=0; i< ITER; i++){
77 MPI_Send(&a[0][0],sizeof(a),MPI_BYTE,1,0,MPI_COMM_WORLD);
80 MPI_Recv(&b[0][0],sizeof(b),MPI_BYTE,0,0,MPI_COMM_WORLD,&status);
86 /* Time sending the same amount of data, with the transpose done
88 MPI_Barrier(MPI_COMM_WORLD);
90 for(k=0; k< ITER; k++){
93 MPI_Send(&a[0][0],sizeof(a),MPI_BYTE,1,0,MPI_COMM_WORLD);
96 MPI_Recv(&b[0][0],sizeof(b),MPI_BYTE,0,0,MPI_COMM_WORLD,&status);
108 /* Print out the results */
110 /* if t and tst are too different, then there is a performance
111 problem in the handling of the datatypes */
115 fprintf( stderr, "Transpose time with datatypes is more than twice time without datatypes\n" );
116 fprintf( stderr, "%f\t%f\t%f\n", t, ts, tst );
121 MPI_Type_free(&xpose);
123 MTest_Finalize( errs );