1 /* Copyright (c) 2016-2019. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "nas_common.h"
8 static double start[64], elapsed[64];
10 /* integer log base two. Return error is argument isn't a power of two or is less than or equal to zero */
15 if (i <= 0) return(-1);
17 for (log2 = 0; log2 < 20; log2++) {
18 if (exp2 == i) return(log2);
24 /* get_info(): Get parameters from command line */
25 void get_info(int argc, char *argv[], int *nprocsp, char *classp)
28 printf("Usage: %s (%d) nprocs class\n", argv[0], argc);
32 *nprocsp = atoi(argv[1]);
36 /* check_info(): Make sure command line data is ok for this benchmark */
37 void check_info(int type, int nprocs, char class)
41 /* check number of processors */
43 printf("setparams: Number of processors must be greater than zero\n");
48 logprocs = ilog2(nprocs);
50 printf("setparams: Number of processors must be a power of two (1,2,4,...) for this benchmark\n");
58 /* never should have gotten this far with a bad name */
59 printf("setparams: (Internal Error) Benchmark type %d unknown to this program\n", type);
64 if (class != 'S' && class != 'W' && class != 'A' && class != 'B' && class != 'C' && class != 'D' && class != 'E') {
65 printf("setparams: Unknown benchmark class %c\n", class);
66 printf("setparams: Allowed classes are \"S\", \"W\", and \"A\" through \"E\"\n");
70 if (class == 'E' && (type == IS || type == DT)) {
71 printf("setparams: Benchmark class %c not defined for IS or DT\n", class);
75 if (class == 'D' && type == IS && nprocs < 4) {
76 printf("setparams: IS class D size cannot be run on less than 4 processors\n");
81 void timer_clear(int n)
86 void timer_start(int n)
88 start[n] = MPI_Wtime();
91 void timer_stop(int n)
93 elapsed[n] += MPI_Wtime() - start[n];
96 double timer_read(int n)
101 double vranlc(int n, double x, double a, double *y)
104 uint64_t i246m1=0x00003FFFFFFFFFFF;
105 uint64_t LLx, Lx, La;
108 // This doesn't work, because the compiler does the calculation in 32 bits and overflows. No standard way (without
109 // f90 stuff) to specifythat the rhs should be done in 64 bit arithmetic.
110 // parameter(i246m1=2**46-1)
116 //fprintf(stdout,("================== Vranlc ================");
117 //fprintf(stdout,("Before Loop: Lx = " + Lx + ", La = " + La);
119 for (i=0; i< n; i++) {
120 Lx = Lx*La & i246m1 ;
122 y[i] = d2m46 * (double)LLx;
125 fprintf(stdout,("After loop 0:");
126 fprintf(stdout,("Lx = " + Lx + ", La = " + La);
127 fprintf(stdout,("d2m46 = " + d2m46);
128 fprintf(stdout,("LLX(Lx) = " + LLX.doubleValue());
129 fprintf(stdout,("Y[0]" + y[0]);
136 fprintf(stdout,("Change: Lx = " + Lx);
137 fprintf(stdout,("=============End Vranlc ================");
143 * FUNCTION RANDLC (X, A)
145 * This routine returns a uniform pseudorandom double precision number in the
146 * range (0, 1) by using the linear congruential generator
148 * x_{k+1} = a x_k (mod 2^46)
150 * where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers
151 * before repeating. The argument A is the same as 'a' in the above formula,
152 * and X is the same as x_0. A and X must be odd double precision integers
153 * in the range (1, 2^46). The returned value RANDLC is normalized to be
154 * between 0 and 1, i.e. RANDLC = 2^(-46) * x_1. X is updated to contain
155 * the new seed x_1, so that subsequent calls to RANDLC using the same
156 * arguments will generate a continuous sequence.
158 * This routine should produce the same results on any computer with at least
159 * 48 mantissa bits in double precision floating point data. On Cray systems,
160 * double precision should be disabled.
162 * David H. Bailey October 26, 1990
164 * IMPLICIT DOUBLE PRECISION (A-H, O-Z)
165 * SAVE KS, R23, R46, T23, T46
168 * If this is the first call to RANDLC, compute R23 = 2 ^ -23, R46 = 2 ^ -46,
169 * T23 = 2 ^ 23, and T46 = 2 ^ 46. These are computed in loops, rather than
170 * by merely using the ** operator, in order to insure that the results are
171 * exact on all systems. This code assumes that 0.5D0 is represented exactly.
173 double randlc(double *X, double*A)
176 static double R23, R46, T23, T46;
177 double T1, T2, T3, T4;
189 for (i=1; i<=23; i++) {
193 for (i=1; i<=46; i++) {
200 /* Break A into two parts such that A = 2^23 * A1 + A2 and set X = N. */
206 /* Break X into two parts such that X = 2^23 * X1 + X2, compute
207 Z = A1 * X2 + A2 * X1 (mod 2^23), and then X = 2^23 * Z + A2 * X2 (mod 2^46). */
212 T1 = A1 * X2 + A2 * X1;
217 T3 = T23 * Z + A2 * X2;
224 void c_print_results(const char *name, char class, int n1, int n2, int n3, int niter, int nprocs_compiled,
225 int nprocs_total, double t, double mops, const char *optype, int passed_verification)
227 printf( "\n\n %s Benchmark Completed\n", name );
228 printf( " Class = %c\n", class );
232 if ( n2 != 0 ) nn *= n2;
233 printf( " Size = %12ld\n", nn ); /* as in IS */
235 printf( " Size = %3dx %3dx %3d\n", n1,n2,n3 );
237 printf( " Iterations = %12d\n", niter );
238 printf( " Time in seconds = %12.2f\n", t );
239 printf( " Total processes = %12d\n", nprocs_total );
241 if ( nprocs_compiled != 0 )
242 printf( " Compiled procs = %12d\n", nprocs_compiled );
244 printf( " Mop/s total = %12.2f\n", mops );
245 printf( " Mop/s/process = %12.2f\n", mops/((float) nprocs_total) );
246 printf( " Operation type = %24s\n", optype);
248 if( passed_verification )
249 printf( " Verification = SUCCESSFUL\n" );
251 printf( " Verification = UNSUCCESSFUL\n" );