// Compile with gcc: // gcc -pg profiletest3.c -oprofiletest3 -lm #include #include // Global variables double *data; // The data. int N; // Size of the data. int numTrials; // Number of trials to use in estimation. int *max; // Store partial maxima. // Random-number generator static r_seed = 12345678L; double uniform () { static long m = 2147483647; static long a = 48271; static long q = 44488; static long r = 3399; long t, lo, hi; hi = r_seed / q; lo = r_seed - q * hi; t = a * lo - r * hi; if (t > 0) r_seed = t; else r_seed = t + m; return ( (double) r_seed / (double) m ); } // Build random array double* makeRandomArray (int length) { int i; double *A = (double*) malloc (sizeof(double) * length); for (i=0; i m) m = data[i]; max[i] = m; } } // Find partial sum: the sum of data[0],...,data[limit]. double findSum (int limit) { int k; double sum; sum = 0; for (k=0; k