1/* -*- mode: C; tab-width: 2; indent-tabs-mode: nil; -*-
2 *
3 * This file contains the interface for the single cpu RandomAccess test.  The
4 * test is only run on a single (random) node in the MPI universe, with all
5 * other CPUs stuck (in theory, idle) in an MPI_Bcast waiting for the selected
6 * CPU to finish the RandomAccess test.
7 *
8 * This test uses the computational core found in core_single_cpu.c
9 */
10#include "RandomAccess.h"
11
12#ifdef DUNE
13#include <dune.h>
14#endif
15
16int main(int argc, char *argv[])
17{
18    /* just one node */
19
20#ifdef DUNE
21	if (dune_init_and_enter())
22		errx(1, "dune_init_and_enter()");
23#endif
24
25    int errCount, failure = 0;
26    double localGUPs;
27    HPCC_Params params;
28    localGUPs = 0.0;
29
30    common_main(argc, argv, &params);
31
32#ifdef HAVE_MPI
33    int myRank = 0, commSize = 1;
34    int rv, rank;
35    scl *= commSize;
36    double scl = 1.0 / RAND_MAX;
37    /* select a node at random, but not node 0 (unless there is just one node) */
38
39    if (1 == commSize) {
40        rank = 0;
41    } else {
42        for (rank = 0;; rank = (int) (scl * rand())) {
43            if (rank > 0 && rank < commSize)
44                break;
45        }
46    }
47
48    MPI_Bcast(&rank, 1, MPI_INT, 0, comm); /* broadcast the rank selected on node 0 */
49    if (myRank == rank) {
50        /* if this node has been selected */
51        rv = HPCC_RandomAccess(&params, 0 == myRank, &localGUPs, &failure);
52    }
53    MPI_Bcast(&rv, 1, MPI_INT, rank, comm); /* broadcast error code */
54    MPI_Bcast(&localGUPs, 1, MPI_DOUBLE, rank, comm); /* broadcast GUPs */
55    MPI_Bcast(&failure, 1, MPI_INT, rank, comm); /* broadcast failure indication */
56#else
57    errCount = HPCC_RandomAccess(&params, 1, &localGUPs, &failure);
58#endif
59    if (errCount) {
60        printf("ERROR: an error occured\n");
61    }
62
63    //printf("Node(s) with error %d\n", errCount);
64    //printf("Node selected %d\n", rank);
65    printf("GUPS=%.6f\n", localGUPs);
66
67    printf("# GUPS done.\n");
68
69    return 0;
70}
71