****************************** Solution D ****************************** NUMERICAL RESULTS ----------------- Tprime,lab: 62850.0 Tgauss,lab: 50.0 Tprime,grendel: 164460.0 Tgauss,grendel: 120.0 Tprime,ozark: 137560.0 Tgauss,ozark: 80.0 Tprime,grendel / Tprime,lab : 2.6167 Tprime,ozark / Tprime,lab : 2.1887 Tgauss,grendel / Tgauss,lab : 2.4 Tgauss,ozark / Tgauss,lab : 1.6 CODE DESCRIPTION ---------------- 1- Representations The above numerical data represent the times taken by three different computers (ozark, grendel, and frodo) to run two sets of instructions (prime testing:Tprime, and Gaussian integral:Tgauss), and the ratios of results for ozark and grendel relative to frodo. The times are reported in milliseconds. 2- Data Collection The results were obtained by logging on each computer separately and running a program called benchmarks. The program runs both the primality test for 68718952447 and computes the gaussian integral for 999999, then logs the results in a file named benchmarks.txt in the current working directory. The working directory is csci330 for grendel, and www for both frodo and ozark. To perform the tests, the program to be run (benchmarks) was copied to both directories (www and csci330). To run it, the computers have been accessed remotely via terminal commands read from a text file (benchmarks.sh). The following was the procedure: the name of the computer was logged in the results file (benchmark.txt) before running the program (benchmarks), and the computers were accessed in this order: ozark, grendel, frodo. After running the program on frodo, the contents of csci330/benchmarks.txt was appended to www/benchmarks.txt, which was downloaded using ftp. 3- Code The primality test and gaussian integral were implemented using C functions in a program named benchmarks. The code for it is appended in the section labeled "benchmarks.c" of the appendix and was compiled using g++. To time the instructions in each function, the clock() function from the time.h library was called both before and after the calling of each function, then the difference between both values was computed and logged in the results file. 4- Choice of test numbers The number for gaussian integral was incrementally chosen to have reasonable running times for the computations. However, the choice was not easy for the prime test, which explains why a very large number was used. For most cases the primality test would report a running time of 0.0000 milliseconds, which was not helpful for a comparison. The number was chosen from a rapidly-growing series called the "Carol primes". Below the chosen one (68718952447, being the ninth in the series), the running time was so short that it was hard to rely on it (mostly zero) and above it the program seemed to take forever. Though the current choice also takes very long (one to two minutes), it appears to be a good one. 5-Timing The sets of instructions were timed approximately. the clock() function used for the timing normally (GNU system) sums up the time used in executing the instructions of the calling process and the time used by the system on behalf of the calling process. It is obvious that only the first (user time) should be considered, but the used timing can nonetheless be representative of the machines' performances. 6- Observations For both tests, ozark appears to be faster than grendel, but slower than frodo. Again refering to the timing used, maybe a slightly different trend or ratio would have been observed if an accurate timing was used (using user time instead of user time + system time). APPENDIX ----------- benchmarks.c ================= #include #include #include #include #define f(n) exp(-(n*n)/2) int primeTest(long); float gaussianInt(int); int main(){ int is_prime; clock_t start, diff1, diff2; long my_prime; int num; float gauss_int; FILE * pFile; const char* bool_var[2] = {"FALSE", "TRUE"}; pFile = fopen ("benchmarks.txt","a"); if(!pFile){ exit(1); } my_prime = 68718952447; num = 999999; //time prime test start = clock(); is_prime = primeTest(my_prime); diff1 = clock() - start; //time gaussian integral start = clock(); gauss_int = gaussianInt(num); diff2 = clock() - start; //log results fprintf(pFile, "---------------------\n"); fprintf(pFile, "Prime testing for n = %ld : %s ; time: %f milliseconds\n", my_prime, bool_var[is_prime], ((float)diff1)*1000/CLOCKS_PER_SEC); fprintf(pFile, "Gaussian integral for n = %d : %f ; time: %f milliseconds\n", num, gauss_int, ((float)diff2)*1000/CLOCKS_PER_SEC); fprintf(pFile, "---------------------\n"); fclose(pFile); return 0; } int primeTest(long n){ int d = 2; while(d*d < n){ if(n%d == 0)return 0; d++; } return 1; } float gaussianInt(int n){ float sum, delta; int i; sum = f(-2) + f(2); delta = 4/n; for (i=1; i benchmarks.txt ./benchmarks exit EXEC_ON_OZARK ssh username@grendel.cs.hendrix.edu<<'EXEC_ON_GRENDEL' cd csci330 echo "--RUN ON GRENDEL --(csci330)--" > benchmarks.txt ./benchmarks exit EXEC_ON_GRENDEL ssh username@frodo.cs.hendrix.edu<<'EXEC_ON_LAB_COMPUTER' cd www echo "--RUN ON FRODO --(www)--" >> benchmarks.txt ./benchmarks cd cat csci330/benchmarks.txt >> www/benchmarks.txt exit EXEC_ON_LAB_COMPUTER sftp username@frodo.cs.hendrix.edu<<'COPY_RESULTS_TO_LOCAL_COMPUTER' lcd results cd www get benchmarks.txt bye COPY_RESULTS_TO_LOCAL_COMPUTER