10 /* This one's binary name. */
11 char* binname = "unset";
15 fprintf (stderr, "\nUsage: %s [-f <string>] [-n <number>]\n", binname);
16 fprintf (stderr, "\t -f: set the filename of the randfile. (defaults to \"numlist.bin\")\n");
17 fprintf (stderr, "\t -n: set the number count to read from randfile. (defaults to -1 = read all)\n");
18 fprintf (stderr, "\nThis application prints only TIME-INFO to stdout. Everything else goes to stderr.\n");
22 void array_contents(numtype array[], unsigned long size) {
23 printf ("[%li", array[0]);
24 for (unsigned long i = 1; i < size; i++) {
25 printf (", %li", array[i]);
31 int main (int argc, char* argv[]) {
35 //unsigned int countarray[NUMBERS];
36 double startTime, endTime;
40 char *filename = "numlist.bin";
42 /* store out name for usage(); */
48 while ((c = getopt (argc, argv, "n:f:")) != -1) switch (c){
50 n = strtoul (optarg,NULL,0);
56 if (optopt == 'f' || optopt == 'n')
57 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
58 else if (isprint (optopt))
59 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
61 fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
68 if ((file = fopen(filename, "r"))) {
74 if (n == -1 || n > size){
78 fprintf (stderr, "File %s does not exist.\n", filename);
82 /* print info and start reading file. */
83 fprintf(stderr, "Will read %li numbers from \"%s\".\n", n, filename);
85 numarray = malloc(n * sizeof(numtype));
86 if(numarray == NULL) {
87 fprintf(stderr, "malloc for numarray failed.\n");
90 fprintf(stderr, "malloc for numarray sucessful.\n");
94 if ((file = fopen(filename, "r"))) {
95 for (size = 0; size < n; size++) {
96 numarray[size] = fgetc(file);
100 fprintf (stderr, "File %s could not be read.\n", filename);
104 fprintf(stderr, "file read - ready.\n");
107 /* might want to comment this out, if numarray is big */
108 array_contents(numarray, size);
111 printf("init done starting algorithm. size: %li\n", size);
112 startTime = omp_get_wtime();
113 algorithm(numarray, size, NULL);
114 endTime = omp_get_wtime();
115 printf("DONE. took %f seconds.\n", endTime-startTime);
116 printf ("result: %li\n", numarray[size-1]);
119 /* might want to comment this out, if numarray is big */
120 array_contents(numarray, size);