Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ec205aa9e91722244040cab46cd4358ac02d84ba
[simgrid.git] / teshsuite / smpi / mpich3-test / perf / twovec.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10 #include "mpi.h"
11
12 /* Make sure datatype creation is independent of data size */
13
14 #define SKIP 4
15 #define NUM_SIZES 16
16 #define FRACTION 0.2
17
18 /* Don't make the number of loops too high; we create so many
19  * datatypes before trying to free them */
20 #define LOOPS 1024
21
22 int main(int argc, char *argv[])
23 {
24     MPI_Datatype column[LOOPS], xpose[LOOPS];
25     double t[NUM_SIZES], ttmp, tmean;
26     int size;
27     int i, j, errs = 0, nrows, ncols;
28
29     MPI_Init(&argc, &argv);
30
31     tmean = 0;
32     size = 1;
33     for (i = 0; i < NUM_SIZES + SKIP; i++) {
34         nrows = ncols = size;
35
36         ttmp = MPI_Wtime();
37
38         for (j = 0; j < LOOPS; j++) {
39             MPI_Type_vector(nrows, 1, ncols, MPI_INT, &column[j]);
40             MPI_Type_hvector(ncols, 1, sizeof(int), column[j], &xpose[j]);
41             MPI_Type_commit(&xpose[j]);
42         }
43
44         if (i >= SKIP) {
45             t[i - SKIP] = MPI_Wtime() - ttmp;
46             tmean += t[i - SKIP];
47         }
48
49         for (j = 0; j < LOOPS; j++) {
50             MPI_Type_free(&xpose[j]);
51             MPI_Type_free(&column[j]);
52         }
53
54         if (i >= SKIP)
55             size *= 2;
56     }
57     tmean /= NUM_SIZES;
58
59     /* Now, analyze the times to see that they are nearly independent
60      * of size */
61     for (i = 0; i < NUM_SIZES; i++) {
62         /* The difference between the value and the mean is more than
63          * a "FRACTION" of mean. */
64         if (fabs(t[i] - tmean) > (FRACTION * tmean))
65             errs++;
66     }
67
68     if (errs) {
69         fprintf(stderr, "too much difference in performance: ");
70         for (i = 0; i < NUM_SIZES; i++)
71             fprintf(stderr, "%.3f ", t[i] * 1e6);
72         fprintf(stderr, "\n");
73     }
74     else
75         printf(" No Errors\n");
76
77     MPI_Finalize();
78     return 0;
79 }