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);
61 for (i = 0; i < ITER; i++) {
63 MPI_Send(&a[0][0], SIZE * SIZE, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD);
65 MPI_Recv(&b[0][0], 1, xpose, 0, 0, MPI_COMM_WORLD, &status);
70 /* Time sending the same amount of data, but without the transpose */
71 MPI_Barrier(MPI_COMM_WORLD);
73 for (i = 0; i < ITER; i++) {
75 MPI_Send(&a[0][0], sizeof(a), MPI_BYTE, 1, 0, MPI_COMM_WORLD);
78 MPI_Recv(&b[0][0], sizeof(b), MPI_BYTE, 0, 0, MPI_COMM_WORLD, &status);
82 ts = (t2 - t1) / ITER;
84 /* Time sending the same amount of data, with the transpose done
85 * as a separate step */
86 MPI_Barrier(MPI_COMM_WORLD);
88 for (k = 0; k < ITER; k++) {
90 MPI_Send(&a[0][0], sizeof(a), MPI_BYTE, 1, 0, MPI_COMM_WORLD);
93 MPI_Recv(&b[0][0], sizeof(b), MPI_BYTE, 0, 0, MPI_COMM_WORLD, &status);
94 for (i = 0; i < SIZE; i++)
95 for (j = i; j < SIZE; j++) {
103 tst = (t2 - t1) / ITER;
105 /* Print out the results */
107 /* if t and tst are too different, then there is a performance
108 * problem in the handling of the datatypes */
113 "Transpose time with datatypes is more than twice time without datatypes\n");
114 fprintf(stderr, "%f\t%f\t%f\n", t, ts, tst);
119 MPI_Type_free(&xpose);
121 MTest_Finalize(errs);