File: run_mpitests.c

package info (click to toggle)
mpich 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 251,828 kB
  • sloc: ansic: 1,323,147; cpp: 82,869; f90: 72,420; javascript: 40,763; perl: 28,296; sh: 19,399; python: 16,191; xml: 14,418; makefile: 9,468; fortran: 8,046; java: 4,635; pascal: 352; asm: 324; ruby: 176; awk: 27; lisp: 19; php: 8; sed: 4
file content (97 lines) | stat: -rw-r--r-- 2,278 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mpitest.h"
#include <stdio.h>
#include <ctype.h>
#include <assert.h>
#include <unistd.h>

#define ARGS_MAX 1024
int wrank, wsize;

#ifdef MULTI_TESTS

#include "multi_tests.c"

#else /* !MULTI_TESTS */
static void concat_argv(char *buf, int max, int argc, char **argv)
{
    int n = 0;
    for (int i = 1; i < argc; i++) {
        int len = strlen(argv[i]);
        if (len > max - n - 1) {
            len = max - n - 1;
        }
        if (n > 0) {
            buf[n++] = ' ';
        }
        strncpy(buf + n, argv[i], len);
        n += len;
    }
    buf[n] = '\0';
}
#endif /* MULTI_TESTS */

int main(int argc, char **argv)
{
    int ret = 0;

#ifdef MULTI_TESTS
    init_multi_tests();
#else
    /* concat argv into args string */
    char args[ARGS_MAX];
    concat_argv(args, ARGS_MAX, argc, argv);
#endif

    MTest_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &wsize);
    MPI_Comm_rank(MPI_COMM_WORLD, &wrank);

#ifdef MULTI_TESTS
    run_fn fn;
    const char *name;
    const char *args;
    /* multi_tests are driven by a script via stdin/stdout */
    while (get_test(&name, &args, &fn)) {
        if (fn) {
            /* reset errhandler in case last test set it to something else */
            MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL);

            int ret = fn(args);
            alarm(0);   /* cancel timeout */
            int toterrs;
            MPI_Reduce(&ret, &toterrs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
            if (wrank == 0) {
                fprintf(test_out, "%s: %d\n", name, toterrs);
                fflush(test_out);
            }
        } else {
            if (wrank == 0) {
                fprintf(test_out, "%s: not found\n", name);
                fflush(test_out);
            }
        }
    }
#else
    ret = run(args);
    int toterrs;
    MPI_Reduce(&ret, &toterrs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
    if (wrank == 0) {
        if (toterrs == 0) {
            printf("No Errors\n");
        } else {
            printf("Found %d errors\n", toterrs);
        }
    }
#endif

#ifdef MULTI_TESTS
    finalize_multi_tests();
#endif
    MPI_Finalize();
    return ret;
}