Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[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, tmean;
35     double tMeanLower, tMeanHigher;
36     int size;
37     int i, j, errs = 0, nrows, ncols;
38
39     MPI_Init(&argc, &argv);
40
41     tmean = 0;
42     size = 1;
43     for (i = -SKIP; i < NUM_SIZES; i++) {
44         nrows = ncols = size;
45
46         ttmp = MPI_Wtime();
47
48         for (j = 0; j < LOOPS; j++) {
49             MPI_Type_vector(nrows, 1, ncols, MPI_INT, &column[j]);
50             MPI_Type_hvector(ncols, 1, sizeof(int), column[j], &xpose[j]);
51             MPI_Type_commit(&xpose[j]);
52         }
53
54         if (i >= 0) {
55             t[i] = MPI_Wtime() - ttmp;
56             if (t[i] < 100 * MPI_Wtick()) {
57                 /* Time is too inaccurate to use.  Set to zero.
58                  * Consider increasing the LOOPS value to make this
59                  * time large enough */
60                 t[i] = 0;
61             }
62             tmean += t[i];
63         }
64
65         for (j = 0; j < LOOPS; j++) {
66             MPI_Type_free(&xpose[j]);
67             MPI_Type_free(&column[j]);
68         }
69
70         if (i >= 0)
71             size *= 2;
72     }
73     tmean /= NUM_SIZES;
74
75     /* Now, analyze the times to see that they do not grow too fast
76      * as a function of size.  As that is a vague criteria, we do the
77      * following as a simple test:
78      * Compute the mean of the first half and the second half of the
79      * data
80      * Compare the two means
81      * If the mean of the second half is more than FRACTION times the
82      * mean of the first half, then the time may be growing too fast.
83      */
84     tMeanLower = tMeanHigher = 0;
85     for (i = 0; i < NUM_SIZES / 2; i++)
86         tMeanLower += t[i];
87     tMeanLower /= (NUM_SIZES / 2);
88     for (i = NUM_SIZES / 2; i < NUM_SIZES; i++)
89         tMeanHigher += t[i];
90     tMeanHigher /= (NUM_SIZES - NUM_SIZES / 2);
91     /* A large value (even 1 or greater) is a good choice for
92      * FRACTION here - the goal is to detect significant growth in
93      * execution time as the size increases, and there is no MPI
94      * standard requirement here to meet.
95      *
96      * If the times were too small, then the test also passes - the
97      * goal is to find implementation problems that lead to excessive
98      * time in these routines.
99      */
100     if (tMeanLower > 0 && tMeanHigher > (1 + FRACTION) * tMeanLower)
101         errs++;
102
103     if (errs) {
104         fprintf(stderr, "too much difference in performance: ");
105         for (i = 0; i < NUM_SIZES; i++)
106             fprintf(stderr, "%.3f ", t[i] * 1e6);
107         fprintf(stderr, "\n");
108     }
109     else
110         printf(" No Errors\n");
111
112     MPI_Finalize();
113     return 0;
114 }