1 /* Copyright (c) 2016. 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 time_clear(double *onetimer) {
85 void time_start(double *onetimer) {
86 *onetimer = MPI_Wtime();
89 void time_stop(int n,double *elapsed,double *start) {
90 elapsed[n] = MPI_Wtime()- start[n];
93 double time_read(int n, double *elapsed) { /* ok, useless, but jsut to keep function call */
97 void timer_clear(int n)
102 void timer_start(int n)
104 start[n] = MPI_Wtime();
107 void timer_stop(int n)
109 elapsed[n] += MPI_Wtime() - start[n];
112 double timer_read(int n)
117 double vranlc(int n, double x, double a, double *y)
120 long i246m1=0x00003FFFFFFFFFFF;
124 // This doesn't work, because the compiler does the calculation in 32 bits and overflows. No standard way (without
125 // f90 stuff) to specifythat the rhs should be done in 64 bit arithmetic.
126 // parameter(i246m1=2**46-1)
132 //fprintf(stdout,("================== Vranlc ================");
133 //fprintf(stdout,("Before Loop: Lx = " + Lx + ", La = " + La);
135 for (i=0; i< n; i++) {
136 Lx = Lx*La & i246m1 ;
138 y[i] = d2m46 * (double)LLx;
141 fprintf(stdout,("After loop 0:");
142 fprintf(stdout,("Lx = " + Lx + ", La = " + La);
143 fprintf(stdout,("d2m46 = " + d2m46);
144 fprintf(stdout,("LLX(Lx) = " + LLX.doubleValue());
145 fprintf(stdout,("Y[0]" + y[0]);
152 fprintf(stdout,("Change: Lx = " + Lx);
153 fprintf(stdout,("=============End Vranlc ================");
159 * FUNCTION RANDLC (X, A)
161 * This routine returns a uniform pseudorandom double precision number in the
162 * range (0, 1) by using the linear congruential generator
164 * x_{k+1} = a x_k (mod 2^46)
166 * where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers
167 * before repeating. The argument A is the same as 'a' in the above formula,
168 * and X is the same as x_0. A and X must be odd double precision integers
169 * in the range (1, 2^46). The returned value RANDLC is normalized to be
170 * between 0 and 1, i.e. RANDLC = 2^(-46) * x_1. X is updated to contain
171 * the new seed x_1, so that subsequent calls to RANDLC using the same
172 * arguments will generate a continuous sequence.
174 * This routine should produce the same results on any computer with at least
175 * 48 mantissa bits in double precision floating point data. On Cray systems,
176 * double precision should be disabled.
178 * David H. Bailey October 26, 1990
180 * IMPLICIT DOUBLE PRECISION (A-H, O-Z)
181 * SAVE KS, R23, R46, T23, T46
184 * If this is the first call to RANDLC, compute R23 = 2 ^ -23, R46 = 2 ^ -46,
185 * T23 = 2 ^ 23, and T46 = 2 ^ 46. These are computed in loops, rather than
186 * by merely using the ** operator, in order to insure that the results are
187 * exact on all systems. This code assumes that 0.5D0 is represented exactly.
189 double randlc(double *X, double*A)
192 static double R23, R46, T23, T46;
193 double T1, T2, T3, T4;
205 for (i=1; i<=23; i++) {
209 for (i=1; i<=46; i++) {
216 /* Break A into two parts such that A = 2^23 * A1 + A2 and set X = N. */
222 /* Break X into two parts such that X = 2^23 * X1 + X2, compute
223 Z = A1 * X2 + A2 * X1 (mod 2^23), and then X = 2^23 * Z + A2 * X2 (mod 2^46). */
228 T1 = A1 * X2 + A2 * X1;
233 T3 = T23 * Z + A2 * X2;
240 void c_print_results(const char *name, char class, int n1, int n2, int n3, int niter, int nprocs_compiled,
241 int nprocs_total, double t, double mops, const char *optype, int passed_verification)
243 printf( "\n\n %s Benchmark Completed\n", name );
244 printf( " Class = %c\n", class );
248 if ( n2 != 0 ) nn *= n2;
249 printf( " Size = %12ld\n", nn ); /* as in IS */
251 printf( " Size = %3dx %3dx %3d\n", n1,n2,n3 );
253 printf( " Iterations = %12d\n", niter );
254 printf( " Time in seconds = %12.2f\n", t );
255 printf( " Total processes = %12d\n", nprocs_total );
257 if ( nprocs_compiled != 0 )
258 printf( " Compiled procs = %12d\n", nprocs_compiled );
260 printf( " Mop/s total = %12.2f\n", mops );
261 printf( " Mop/s/process = %12.2f\n", mops/((float) nprocs_total) );
262 printf( " Operation type = %24s\n", optype);
264 if( passed_verification )
265 printf( " Verification = SUCCESSFUL\n" );
267 printf( " Verification = UNSUCCESSFUL\n" );