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 11#include "RandomAccess.h" 12#ifdef DUNE 13#include <dune.h> 14#endif 15 16int main(int argc, char *argv[]) 17{ 18 19 int errCount, failure = 0; 20 double localGUPs; 21 22 HPCC_Params params; 23 localGUPs = 0.0; 24 25#ifdef DUNE 26 if (dune_init_and_enter()) 27 errx(1, "dune_init_and_enter()"); 28#endif 29 30 common_main(argc, argv, ¶ms); 31 32#ifdef HAVE_MPI 33 int rv, rank; 34 int myRank, commSize; 35 double scl = 1.0 / RAND_MAX; 36 FILE *outputFile = NULL; 37 MPI_Comm comm = MPI_COMM_WORLD; 38 MPI_Comm_size( comm, &commSize ); 39 MPI_Comm_rank( comm, &myRank ); 40 scl *= commSize; 41 42 /* select a node at random, but not node 0 (unless there is just one node) */ 43 if (1 == commSize) 44 rank = 0; 45 else 46 for (rank = 0;; rank = (int)(scl * rand())) { 47 if (rank > 0 && rank < commSize) 48 break; 49 } 50 51 MPI_Bcast( &rank, 1, MPI_INT, 0, comm ); /* broadcast the rank selected on node 0 */ 52 53 if (myRank == rank) /* if this node has been selected */ 54 rv = HPCC_RandomAccess_LCG( params, 0 == myRank, &localGUPs, &failure ); 55 56 MPI_Bcast( &rv, 1, MPI_INT, rank, comm ); /* broadcast error code */ 57 MPI_Bcast( &localGUPs, 1, MPI_DOUBLE, rank, comm ); /* broadcast GUPs */ 58 MPI_Bcast( &failure, 1, MPI_INT, rank, comm ); /* broadcast failure indication */ 59 errCount = rv; 60 params->Single_LCG_GUPs = localGUPs; 61 if (failure) params->Failure = 1; 62#else 63 errCount = HPCC_RandomAccess_LCG( ¶ms, 1, &localGUPs, &failure ); 64#endif 65 66 //printf("Node(s) with error %d\n", errCount); 67 //printf("Node selected %d\n", rank); 68 printf("GUPS=%.6f\n", localGUPs); 69 70 printf("# GUPS done.\n"); 71 72 return 0; 73} 74