Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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    Note, however, that there is no guarantee or expectation
14    that the time would be constant.  In particular, some
15    optimizations might take more time than others.
16
17    The real goal of this is to ensure that the time to create
18    a datatype doesn't increase strongly with the number of elements
19    within the datatype, particularly for these datatypes that are
20    quite simple patterns.
21  */
22
23 #define SKIP 4
24 #define NUM_SIZES 16
25 #define FRACTION 1.0
26
27 /* Don't make the number of loops too high; we create so many
28  * datatypes before trying to free them */
29 #define LOOPS 1024
30
31 int main(int argc, char *argv[])
32 {
33     MPI_Datatype column[LOOPS], xpose[LOOPS];
34     double t[NUM_SIZES], ttmp;
35     double tMeanLower, tMeanHigher;
36     int size;
37     int i, j, errs = 0, nrows, ncols;
38
39     MPI_Init(&argc, &argv);
40
41     size = 1;
42     for (i = -SKIP; i < NUM_SIZES; i++) {
43         nrows = ncols = size;
44
45         ttmp = MPI_Wtime();
46
47         for (j = 0; j < LOOPS; j++) {
48             MPI_Type_vector(nrows, 1, ncols, MPI_INT, &column[j]);
49             MPI_Type_hvector(ncols, 1, sizeof(int), column[j], &xpose[j]);
50             MPI_Type_commit(&xpose[j]);
51         }
52
53         if (i >= 0) {
54             t[i] = MPI_Wtime() - ttmp;
55             if (t[i] < 100 * MPI_Wtick()) {
56                 /* Time is too inaccurate to use.  Set to zero.
57                  * Consider increasing the LOOPS value to make this
58                  * time large enough */
59                 t[i] = 0;
60             }
61         }
62
63         for (j = 0; j < LOOPS; j++) {
64             MPI_Type_free(&xpose[j]);
65             MPI_Type_free(&column[j]);
66         }
67
68         if (i >= 0)
69             size *= 2;
70     }
71
72     /* Now, analyze the times to see that they do not grow too fast
73      * as a function of size.  As that is a vague criteria, we do the
74      * following as a simple test:
75      * Compute the mean of the first half and the second half of the
76      * data
77      * Compare the two means
78      * If the mean of the second half is more than FRACTION times the
79      * mean of the first half, then the time may be growing too fast.
80      */
81     tMeanLower = tMeanHigher = 0;
82     for (i = 0; i < NUM_SIZES / 2; i++)
83         tMeanLower += t[i];
84     tMeanLower /= (NUM_SIZES / 2);
85     for (i = NUM_SIZES / 2; i < NUM_SIZES; i++)
86         tMeanHigher += t[i];
87     tMeanHigher /= (NUM_SIZES - NUM_SIZES / 2);
88     /* A large value (even 1 or greater) is a good choice for
89      * FRACTION here - the goal is to detect significant growth in
90      * execution time as the size increases, and there is no MPI
91      * standard requirement here to meet.
92      *
93      * If the times were too small, then the test also passes - the
94      * goal is to find implementation problems that lead to excessive
95      * time in these routines.
96      */
97     if (tMeanLower > 0 && tMeanHigher > (1 + FRACTION) * tMeanLower)
98         errs++;
99
100     if (errs) {
101         fprintf(stderr, "too much difference in performance: ");
102         for (i = 0; i < NUM_SIZES; i++)
103             fprintf(stderr, "%.3f ", t[i] * 1e6);
104         fprintf(stderr, "\n");
105     }
106     else
107         printf(" No Errors\n");
108
109     MPI_Finalize();
110     return 0;
111 }