1 /*********************************************************************
2 Serial Test
3 *********************************************************************/
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cstring>
7 #include "tests.h"
8
9 #ifdef SPRNG_MPI
10 #include <mpi.h>
11 #endif
12
13 using namespace std;
14
15 /* # of parameters for the test engin */
16 #define NUM_TEST_ENGIN_PARAM 2
17 /* # of divisions between [0,1) */
18 static long numDiv;
19 /* # of random-numbers pairs being tested */
20 static long numPair;
21 /* # of bins */
22 static long numBin;
23 /* # of tests repeated */
24 static long numRepeat;
25 /* Array of bins */
26 static long *bins;
27 /* Array of corresponding probabilities */
28 static double *probs;
29 /* Array of chi-squares */
30 static double *chiSqrs;
31
32 /********************************************************************/
33 #define FATAL_ABORT printf("Program terminated.\n"); exit(0)
34
35 /*------------------------------------------------------------------*/
36
initTest(int argc,char * argv[])37 void initTest(int argc, char *argv[]) {
38 int numParam=NUM_TEST_ENGIN_PARAM+N_STREAM_PARAM;
39 long index;
40 double temp;
41
42 if (argc<(numParam+1)) {
43 printf("Error: %i number of parameters needed\n", numParam);
44 FATAL_ABORT;
45 }
46
47 numDiv = atol(argv[N_STREAM_PARAM+1]);
48 numPair = atol(argv[N_STREAM_PARAM+2]);
49 if ((numDiv<=0) || (numPair<=0)) {
50 printf("Error: incorrect parameter value(s)\n");
51 FATAL_ABORT;
52 }
53 numBin = numDiv * numDiv;
54 numRepeat = init_tests(argc, argv);
55
56 bins = new long int[numBin];
57 probs = new double[numBin];
58 chiSqrs = new double[NTESTS];
59
60 temp = 1.0 / numBin;
61 for (index=0;index<numBin;index++) probs[index] = temp;
62 }
63
64 /*------------------------------------------------------------------*/
65
deinitTest(void)66 void deinitTest(void) {
67 delete [] bins;
68 delete [] probs;
69 delete [] chiSqrs;
70 }
71
72 /*------------------------------------------------------------------*/
73 #define PROC_ONE_PAIR { \
74 long binIndex; \
75 \
76 binIndex = static_cast<long int>(get_rn() * numDiv); \
77 binIndex *= numDiv; \
78 binIndex += static_cast<long int>(get_rn() * numDiv); \
79 bins[binIndex]++; \
80 }
81
82 /********************************************************************/
83
main(int argc,char * argv[])84 int main(int argc, char *argv[]) {
85 long curRound, index;
86 double KSvalue, KSprob;
87 int Bins_used;
88
89 initTest(argc, argv);
90 for (curRound=0;curRound<numRepeat;curRound++) {
91 for (index=0;index<numBin;index++)
92 bins[index] = 0;
93 for (index=0;index<numPair;index++)
94 PROC_ONE_PAIR;
95
96 chiSqrs[curRound] = chisquare(bins, probs, numPair, numBin, &Bins_used);
97 /*printf("\tChisquare for stream = %f, %% = %f\n", chiSqrs[curRound],
98 chipercent(chiSqrs[curRound],numBin-1));*/
99 next_stream();
100 }
101
102 #if defined(SPRNG_MPI)
103 getKSdata(chiSqrs,NTESTS);
104 #endif
105
106 if(proc_rank == 0)
107 {
108 set_d_of_f(Bins_used-1);
109 KSvalue = KS(chiSqrs, NTESTS, chiF);
110 KSprob = KSpercent(KSvalue, NTESTS);
111
112 printf("Result: KS value = %f\n", (float) KSvalue);
113 printf(" KS value prob = %f %%\n\n", (float) KSprob*100);
114 deinitTest();
115 }
116
117 #if defined(SPRNG_MPI)
118 MPI_Finalize();
119 #endif
120
121 return 0;
122 }
123