int main(int argc, char *argv[]) { int rt1, rt2; pthread_t t1, t2; struct timespec start; struct timespec stop; unsigned long long total; runs = atoi(argv[1]); c = 0; /* set single processor */ single_proc(); /* create 2 threads */ clock_gettime(CLOCK_MONOTONIC, &start); if( (rt1=pthread_create( &t1, NULL, &fn0, NULL)) ) printf("Thread creation failed: %d\n", rt1); if( (rt2=pthread_create( &t2, NULL, &fn1, NULL)) ) printf("Thread creation failed: %d\n", rt2); pthread_join(t1, NULL); pthread_join(t2, NULL); clock_gettime(CLOCK_MONOTONIC, &stop); total = timespecDiff(&stop,&start); printf("CLOCK_MONOTONIC Measured: %lld\n",(total-runtime0-runtime1) / (2*runs)); return 0; }
int main() { struct timespec tstart, tend; int m; int DIM=10000+1; int MM=4000; #ifdef try_TS if ( clock_gettime(CLOCK_MONOTONIC, &tstart)!=0 ) exit(1); TS_make(DIM,MM,0.5); if ( clock_gettime(CLOCK_MONOTONIC, &tend)!=0 ) exit(1); printf("TS_make(%d,%d) took %lf ms\n", DIM, MM, timespecDiff(&tend, &tstart)/1.0e6); #endif if ( clock_gettime(CLOCK_MONOTONIC, &tstart)!=0 ) exit(1); S_make(DIM,MM,0.5); if ( clock_gettime(CLOCK_MONOTONIC, &tend)!=0 ) exit(1); printf("S_make(%d,%d) took %lf ms\n", DIM, MM, timespecDiff(&tend, &tstart)/1.0e6); fS_make(0.5); if ( clock_gettime(CLOCK_MONOTONIC, &tstart)!=0 ) exit(1); T_make(DIM,MM,0.5); if ( clock_gettime(CLOCK_MONOTONIC, &tend)!=0 ) exit(1); printf("T_make(%d,%d) took %lf ms\n", DIM, MM, timespecDiff(&tend, &tstart)/1.0e6); fT_make(DIM,MM,0.5); for (m=10; m<MM; m+=10) printf("(%d,%d): S=%10lg fS=%10g T=%10lg fT=%10g\n", DIM-1, m, exp(S_safe(DIM-1,m)-S_safe(DIM-1,m-1)), exp(fS_safe(DIM-1,m)-fS_safe(DIM-1,m-1)), T_V(DIM-1,m), fT_V(DIM-1,m) ); #ifdef try_TS for (m=10; m<MM; m+=10) printf("(%d,%d): S=%10lg TS=%10lg tbl=%10lg\n", DIM-1, m, S_safe(DIM-1,m), TS_safe(DIM-1,m), TStbl[m-2][DIM-2] ); #endif return 1; }
void android_main(struct android_app *state) { system("su -c \"chmod 0777 /dev/ttyUSB0\""); app_dummy(); state->userData=NULL; state->onAppCmd=engine_handle_cmd; state->onInputEvent=engine_handle_input; app=state; assetManager=state->activity->assetManager; SerialConnect("/dev/ttyUSB0"); while(1) { int ident, events; struct android_poll_source *source; while((ident=ALooper_pollAll(0, NULL, &events, (void**)&source))>=0) { if(source!=NULL) source->process(state, source); if(state->destroyRequested!=0) { engine_term_display(); return; } } memcpy(&StartTime, &EndTime, sizeof(struct timespec)); clock_gettime(CLOCK_MONOTONIC, &EndTime); engine_draw_frame(); fTimeStep=(float)timespecDiff(&EndTime, &StartTime)/1000000000.0f; fTime+=fTimeStep; FPSTemp+=1.0f/fTimeStep; if(Frames++>15) { FPS=FPSTemp/Frames; FPSTemp=0.0f; Frames=0; } } close(tty_fd); }
void FpS::measure() { fps_counter++; if (fps_counter == 10) { clock_gettime(CLOCK_MONOTONIC, &fps_time_end); uint64_t timeElapsed = timespecDiff(&fps_time_end, &fps_time_start); fps = (double)1000000000 / (double)timeElapsed * fps_counter; clock_gettime(CLOCK_MONOTONIC, &fps_time_start); fps_counter = 0; } }
void run_test(int nargs, char* args[]) { if (nargs < 2) { return; } struct timespec start, end; char* dbname = args[1]; drop_buffer_cache(); trace_loader_t loader; load_trace(&loader, args[2], atoi(args[3])); struct MetaDB mdb; metadb_init(&mdb, dbname); enable_monitor_thread(&mdb); clock_gettime(CLOCK_MONOTONIC, &start); get_metric(); if (strcmp(args[4], "create") == 0) { run_create(mdb, &loader, atoi(args[5])); } else { run_query(mdb, &loader, atoi(args[5]), atoi(args[6]), atoi(args[7])); } clock_gettime(CLOCK_MONOTONIC, &end); disable_monitor_thread(); metadb_close(mdb); get_metric(); uint64_t timeElapsed = timespecDiff(&end, &start); timeElapsed = timespecDiff(&end, &start); printf("%s.%d %d %.1f \n", args[4], num_test, (int) time(NULL), timeElapsed/1.0); destroy_trace_loader(&loader); drop_buffer_cache(); }
int main() { struct timespec start; struct timespec stop; unsigned long long result; //64 bit integer clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); getpid(); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop); result=timespecDiff(&stop,&start); printf("Minimal System call Measured: %llu\n",result); return 0; }
void timeMeasure::stop(void) { switch (m_mode) { case GETTIME: clock_gettime(CLOCK_MONOTONIC, &m_stopTime); m_diffTime = timespecDiff(m_startTime, m_stopTime); break; case RDTSC: m_stopTick = readRdtsc(); m_diffTick = m_stopTick - m_startTick; m_diffTime = tickToTimespec(m_diffTick); break; } timespecNorm(&m_diffTime); m_sampleVector.push_back(m_diffTime); }
void *fn1() { struct timespec start1; struct timespec stop1; int run = 0; pthread_mutex_lock(&count_mutex); if (c == 1) { pthread_cond_wait(&cond1, &count_mutex); } while (c == 0) { clock_gettime(CLOCK_MONOTONIC, &start1); c = 1; pthread_cond_signal(&cond0); clock_gettime(CLOCK_MONOTONIC, &stop1); runtime1 += timespecDiff(&stop1, &start1); if (++run > runs) { break; } pthread_cond_wait(&cond1, &count_mutex); } pthread_mutex_unlock(&count_mutex); }
void *fn0() { int run = 0; struct timespec start0; struct timespec stop0; pthread_mutex_lock(&count_mutex); if (c == 0) { pthread_cond_wait(&cond0, &count_mutex); } while (c == 1) { clock_gettime(CLOCK_MONOTONIC, &start0); c = 0; pthread_cond_signal(&cond1); clock_gettime(CLOCK_MONOTONIC, &stop0); runtime0 += timespecDiff(&stop0, &start0); if (++run > runs) { break; } pthread_cond_wait(&cond0, &count_mutex); } pthread_mutex_unlock(&count_mutex); }
node *readIndexBtree(char *index) { struct timespec start, stop; node *root = NULL; FILE *fi; off_t fileLen; off_t pos; off_t *value; int gi; int count = 0; clock_gettime(CLOCK_MONOTONIC, &start); fi = fopen(index, "rb"); if (!fi) { printf("Unable to open file!"); return; } fseeko(fi, 0, SEEK_END); fileLen = ftello(fi); fseeko(fi, 0, SEEK_SET); pos = 0; while (pos < fileLen) { value = malloc(sizeof (off_t)); fread(&gi, sizeof (int), 1, fi); fread(value, sizeof (off_t), 1, fi); root = insert(root, gi, value); pos = ftell(fi); count++; } fclose(fi); clock_gettime(CLOCK_MONOTONIC, &stop); printf("\n\tThere are %d GIs into the B+Tree. Elapsed time: %lu sec\n\n", count, timespecDiff(&stop, &start) / 1000000000); fflush(NULL); return root; }
int main(int argc, char **argv) { struct timespec start, end , p_start, p_end; clock_gettime(CLOCK_MONOTONIC, &start); int c; int num_threads = 4; int img = 1; bool * received_fragments = calloc(N, sizeof(bool)); png_byte * output_buffer = calloc(WIDTH*HEIGHT*4, sizeof(png_byte)); while ((c = getopt (argc, argv, "t:i:")) != -1) { switch (c) { case 't': num_threads = strtoul(optarg, NULL, 10); if (num_threads == 0) { printf("%s: option requires an argument > 0 -- 't'\n", argv[0]); return -1; } break; case 'i': img = strtoul(optarg, NULL, 10); if (img == 0) { printf("%s: option requires an argument > 0 -- 'i'\n", argv[0]); return -1; } break; default: return -1; } } CURLcode global_init = curl_global_init(CURL_GLOBAL_NOTHING); if (global_init) abort_("[main] could not initialize curl"); struct shared_res shared_resource0 = {received_fragments, output_buffer, img, 0}; struct shared_res shared_resource1 = {received_fragments, output_buffer, img, 1}; struct shared_res shared_resource2 = {received_fragments, output_buffer, img, 2}; //struct shared_res * pshared_resource = &shared_resource; pthread_t thread [num_threads]; clock_gettime(CLOCK_MONOTONIC, &p_start); for (int i = 0; i < num_threads; ++i) { if (i%3 == 0){ pthread_create (& thread [i] , NULL , thread_callback, &shared_resource0); } else if (i%3 == 1){ pthread_create (& thread [i] , NULL , thread_callback, &shared_resource1); } else{ pthread_create (& thread [i] , NULL , thread_callback, &shared_resource2); } } for (int i = 0; i < num_threads; ++i) { pthread_join ( thread [i] , NULL ); } clock_gettime(CLOCK_MONOTONIC, &p_end); pthread_mutex_destroy(&mutex1); pthread_mutex_destroy(&mutex2); // now, write the array back to disk using write_png_file png_bytep * output_row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * HEIGHT); for (int i = 0; i < HEIGHT; i++) output_row_pointers[i] = &output_buffer[i*WIDTH*4]; write_png_file("output.png", output_row_pointers); free(output_row_pointers); free(output_buffer); free(received_fragments); curl_global_cleanup(); clock_gettime(CLOCK_MONOTONIC, &end); int64_t p_time_spent_int = timespecDiff(&p_end, &p_start); double p_time_spent = (double)p_time_spent_int; int64_t time_spent_int = timespecDiff(&end, &start); double time_spent = (double)time_spent_int; printf("parallel time = %g\n", p_time_spent/1000000000); printf("total time = %g\n", time_spent/1000000000); return 0; }
/* * Main function */ int main(int argc, char** argv) { struct timespec start, stop; int next_option, verbose, write; const char* const short_options = "hvn:g:o:s:i:"; char *giIndex = NULL; char *includeIndex = NULL; char *skipIndex = NULL; clock_gettime(CLOCK_MONOTONIC, &start); program_name = argv[0]; const struct option long_options[] = { { "help", 0, NULL, 'h'}, { "verbose", 0, NULL, 'v'}, { "nt", 1, NULL, 'n'}, { "gi", 1, NULL, 'g'}, { "nodes", 1, NULL, 'o'}, { "skip", 1, NULL, 's'}, { "include", 1, NULL, 'i'}, { "dbSize", 1, NULL, 'd'}, { NULL, 0, NULL, 0} /* Required at end of array. */ }; write = verbose = 0; nt = gi = nodes = skip = include = NULL; do { next_option = getopt_long(argc, argv, short_options, long_options, NULL); switch (next_option) { case 'h': print_usage(stdout, 0); case 'v': verbose = 1; break; case 'n': nt = (char *) malloc(sizeof (char) * (strlen(optarg) + 1)); strcpy(nt, optarg); break; case 'g': gi = (char *) malloc(sizeof (char) * (strlen(optarg) + 1)); strcpy(gi, optarg); break; case 'o': nodes = (char *) malloc(sizeof (char) * (strlen(optarg) + 1)); strcpy(nodes, optarg); break; case 's': skip = (char *) malloc(sizeof (char) * (strlen(optarg) + 1)); strcpy(skip, optarg); break; case 'i': include = (char *) malloc(sizeof (char) * (strlen(optarg) + 1)); strcpy(include, optarg); break; case 'd': MaxGb = atoi(optarg); break; } } while (next_option != -1); InputCheck(nt, gi, nodes, skip, include); if(verbose == 1) print_parameters(); if(verbose == 1) printf("Getting biggest GI id from %s\n", gi); GetMaxGiNuclDmp(gi); if(verbose == 1) printf("Importing GI and taxon ID pairs into memory from %s\n", gi); ImportGiNuclDmp(gi); if(verbose == 1) printf("Getting biggest taxon ID from %s\n", nodes); GetMaxNodeslDmp(nodes); if(verbose == 1) printf("Importing taxon parent and child IDs into memory from %s\n", nodes); ImportNodeslDmp(nodes); if(include != NULL) { if(verbose == 1) printf("Importing include taxon IDs from %s\n", include); ImportInclude(include); } if(skip != NULL) { if(verbose == 1) printf("Importing exclude taxon IDs from %s\n", skip); ImportExclude(skip); } if(verbose == 1) printf("Reading and parsing fasta file %s\n", nt); ReadFasta(nt); if (nt) free(nt); if (gi) free(gi); if (nodes) free(nodes); if (skip) free(skip); if (include) free(include); FreeIncludeExclude(); FreeGiId(); FreeTaxons(); clock_gettime(CLOCK_MONOTONIC, &stop); printf("\n\tThe total time was %lu sec\n\n", timespecDiff(&stop, &start) / 1000000000); return 0; }
void createBTreeIndex(char *text, char *bin, char *index, char *output, int verbose) { int i, j, k; struct timespec start, stop; node *root; node *assign = NULL; FILE *fb; FILE *ft; FILE *fo; record *rec; genBank_t *g = NULL; int count = 0; char *line = NULL; size_t len = 0; ssize_t read; off_t oTotal, oCurr; int taxId; int gi; float score; int pFrom; int pTo; int noGene = 0; fb = fopen(bin, "rb"); if (!fb) { fprintf(stdout, "Unable to open file %s\n", bin); exit(-1); } ft = fopen(text, "r"); if (!ft) { fprintf(stdout, "Unable to open file %s\n", text); exit(-1); } fo = fopen(output, "w"); if (!fo) { fprintf(stdout, "Unable to open file %s\n", output); exit(-1); } root = readIndexBtree(index); fseeko(ft, 0, SEEK_END); oTotal = ftello(ft); fseeko(ft, 0, SEEK_SET); k = 1; printf("Performing the gene assignment ... \n"); fflush(NULL); clock_gettime(CLOCK_MONOTONIC, &start); while ((read = getline(&line, &len, ft)) != -1) { oCurr = ftello(ft); if ((i = sscanf(line, "%*s\t%d\t%d\t%f\t%d\t%d", &taxId, &gi, &score, &pFrom, &pTo)) == 5) { clock_gettime(CLOCK_MONOTONIC, &stop); j = timespecDiff(&stop, &start) / 1000000000; if (verbose) { printf("\tLines reads %d. Reads without genes %d. GIs with genes %d. Elapsed time %lu sec. Estimated time %lu sec.\r", k, noGene, count, j, (j * oTotal / oCurr)); } rec = find(root, gi, false); if (rec != NULL) { if (!assignGenes(&assign, &g, &count, fb, *((off_t *) rec->value), pFrom, pTo)) { noGene++; } } else { noGene++; } k++; } else { printf("Can't parse the line: %d\t", i); printf("[[%s]]\n", line); exit(-1); } } printf("\tLines reads %d. Reads without genes %d. GIs with genes %d. Elapsed time %lu sec. Estimated time %lu sec.\n", k++, noGene, count, j, (j * oTotal / oCurr)); fflush(NULL); if (line) free(line); line = malloc(sizeof (char) * 1); len = 1; if (g != NULL) { qsort(g, count, sizeof (genBank_t), cmpGenBank); for (i = 0; i < count; i++) { if (g[i].cds != NULL) { qsort(g[i].cds, g[i].cds_number, sizeof (cds_t), cmpCDSSum); for (j = 0; j < g[i].cds_number; j++) { line[0] = '\0'; if (g[i].cds[j].cog_number != 0) { for (k = 0; k < g[i].cds[j].cog_number; k++) { if (len <= strlen(line) + strlen(g[i].cds[j].cog[k]) + 2) { len += strlen(g[i].cds[j].cog[k]) + 2; if (k < g[i].cds[j].cog_number - 1) len++; line = (char *) realloc(line, sizeof (char) * len); } strcat(line, g[i].cds[j].cog[k]); if (k < g[i].cds[j].cog_number - 1) { strcat(line, ","); } } if (strlen(line) + 3 < len) { len += 3; line = (char *) realloc(line, sizeof (char) * len); } strcat(line, "\t"); } else { if (len < 3) { len = 3; line = (char *) realloc(line, sizeof (char) * len); } strcat(line, "-\t"); } if (g[i].cds[j].protClust_number != 0) { for (k = 0; k < g[i].cds[j].protClust_number; k++) { if (len <= strlen(line) + strlen(g[i].cds[j].protClust[k]) + 2) { len += strlen(g[i].cds[j].protClust[k]) + 2; if (k < g[i].cds[j].protClust_number - 1) len++; line = (char *) realloc(line, sizeof (char) * len); } strcat(line, g[i].cds[j].protClust[k]); if (k < g[i].cds[j].protClust_number - 1) { strcat(line, ","); } } } else { if (strlen(line) + 4 > len) { len += 4; line = (char *) realloc(line, sizeof (char) * len); } strcat(line, "-"); } fprintf(fo, "%s\t%d\t%s\t%s\t%d\t%s\n", g[i].locusName, g[i].taxId, g[i].cds[j].proteinId, g[i].cds[j].locusName, g[i].cds[j].hits, line); freeCDS(g[i].cds + j); } free(g[i].cds); } if (g[i].locusName) free(g[i].locusName); } free(g); } destroy_tree(assign, freeDataAssign); destroy_tree(root, freeData); if (line) free(line); fclose(fb); fclose(ft); fclose(fo); }
int main(int argc, char *argv[]) { int iGlobalSize = 1; int iCheck1, iCheck2, iCheck3, iCheck4; size_t iGlobalWorkSize = -1; size_t iLocalWorkSize = -1; if (argc > 1) // Size of input vector { iCheck1 = atoi(argv[1]); if (iCheck1 != 0) { iGlobalSize = iCheck1; } } int iNoReps = 100; // Number of repetitions. if (argc > 2) { iCheck2 = atoi(argv[2]); if (iCheck2 != 0) { iNoReps = iCheck2; } } /* if (argc > 3) // Global work size { iCheck3 = atoi(argv[3]); if (iCheck3 != 0) { iGlobalWorkSize = iCheck3; } } if (argc > 4) // Local work size { iCheck4 = atoi(argv[4]); if (iCheck4 != 0) { iLocalWorkSize = iCheck4; } } */ int bPrint = 0; if (argc > 3) // Originally 5. { bPrint = 1; } // printf("The global size is %d, the global work size is %ld, and the local work size is %ld. \n", iGlobalSize, iGlobalWorkSize, iLocalWorkSize); /* size_t * ipGlobalWorkParam = NULL; if (iGlobalWorkSize != -1) { ipGlobalWorkParam = &iGlobalWorkSize; } size_t * ipLocalWorkParam = NULL; if (iLocalWorkSize != -1) { ipLocalWorkParam = &iLocalWorkSize; } */ GCAQ * TheGCAQ = GCAQSetup(); if (TheGCAQ == NULL) { return 1; } #if BIGFLOAT const char *szFloatOpt = "-DBIGFLOAT"; #else const char *szFloatOpt = NULL; #endif const int iNoKernels = 1; char *ourKernelStrings[6] = { szDotProduct, szReduce, szDotProduct2, szReduce2, szDotProduct4, szReduce4}; GPAK *TheGPAK = GPAKSetup(TheGCAQ, iNoKernels, ourKernelStrings, szFloatOpt); if (TheGPAK == NULL) { GCAQShutdown(TheGCAQ); return 2; } INTG iTypicalWorkgroupNo = TheGPAK->TheMaxWorkGroupSizes[0]; INTG iExpOutputSize = ioutsize(iGlobalSize, iTypicalWorkgroupNo); FLPT * fExpDotProdResult = (FLPT *) malloc(iExpOutputSize * sizeof(FLPT)); FLPT * fExpReduceResult = (FLPT *) malloc(iExpOutputSize * sizeof(FLPT)); fdotprodexpresult(iGlobalSize, iTypicalWorkgroupNo, fExpDotProdResult); freduceexpresult(iGlobalSize, iTypicalWorkgroupNo, fExpReduceResult); // printvector("dot prod", iExpOutputSize, fExpDotProdResult); // printvector("reduce", iExpOutputSize, fExpReduceResult); FLPT* inputDataF = (FLPT *) malloc(iGlobalSize * sizeof(FLPT)); SetFIncrease(iGlobalSize, inputDataF); // For the dot product. FLPT* outputDataD = (FLPT *) malloc(iGlobalSize * sizeof(FLPT)); SetFNull(iGlobalSize, outputDataD); // For the reduction. FLPT* outputDataR = (FLPT *) malloc(iGlobalSize * sizeof(FLPT)); SetFNull(iGlobalSize, outputDataR); struct timespec start[iNoKernels]; struct timespec end[iNoKernels]; // create buffers for the input and ouput int err; cl_mem inputF, outputF, outputAll; inputF = clCreateBuffer(TheGCAQ->TheContext, CL_MEM_READ_ONLY, iGlobalSize * sizeof(FLPT), NULL, &err); if (err != CL_SUCCESS) { printf("Error allocating for F"); return 3; } outputF = clCreateBuffer(TheGCAQ->TheContext, CL_MEM_WRITE_ONLY, iGlobalSize * sizeof(float), NULL, &err); if (err != CL_SUCCESS) { printf("Error allocating for output 7"); return 9; } outputAll = clCreateBuffer(TheGCAQ->TheContext, CL_MEM_WRITE_ONLY, iGlobalSize * sizeof(float), NULL, &err); if (err != CL_SUCCESS) { printf("Error allocating for output 8"); return 9; } clEnqueueWriteBuffer(TheGCAQ->TheQueue, inputF, CL_TRUE, 0, iGlobalSize * sizeof(FLPT), inputDataF, 0, NULL, NULL); int iRep; int iKernel; int i; int iLengthTotal = iGlobalSize; size_t iGlobalWorkThing = iGlobalSize; int iSomething = 1; for (iKernel = 0; iKernel < iNoKernels; iKernel++) { for (i = 0; i < iLengthTotal; i++) { outputDataD[i] = 0.0; outputDataR[i] = 0.0; } clock_gettime(CLOCK_MONOTONIC, &(start[iKernel])); for (iRep = 0; iRep < iNoReps; iRep++) { clSetKernelArg(TheGPAK->TheKernels[iKernel], 0, sizeof(int), &iLengthTotal); clSetKernelArg(TheGPAK->TheKernels[iKernel], 1, sizeof(cl_mem), &inputF); clSetKernelArg(TheGPAK->TheKernels[iKernel], 2, iSomething * iLocalWorkSize * sizeof(float), NULL); // Was 3 clSetKernelArg(TheGPAK->TheKernels[iKernel], 3, sizeof(cl_mem), &outputAll); // Was 4 clEnqueueNDRangeKernel(TheGCAQ->TheQueue, TheGPAK->TheKernels[iKernel], 1, NULL, &iGlobalWorkThing, &(TheGPAK->TheMaxWorkGroupSizes[iKernel]), 0, NULL, NULL); clFinish(TheGCAQ->TheQueue); // copy the results from out of the output buffer if (iKernel % 2 == 0) { clEnqueueReadBuffer(TheGCAQ->TheQueue, outputAll, CL_TRUE, 0, iExpOutputSize * sizeof(float), outputDataD, 0, NULL, NULL); } else { clEnqueueReadBuffer(TheGCAQ->TheQueue, outputAll, CL_TRUE, 0, iExpOutputSize * sizeof(float), outputDataR, 0, NULL, NULL); } } clock_gettime(CLOCK_MONOTONIC, &(end[iKernel])); if (bPrint) { for (i = 0; i < iExpOutputSize; i++) { if (iKernel % 2 == 0) { if (outputDataD[i] != fExpDotProdResult[i]) { printf ("A problem at kernel %d and iteration %d for actual value %f but expected value %f!\n", iKernel, i, outputDataD[i], fExpDotProdResult[i]); break; } } else { if (outputDataR[i] != fExpReduceResult[i]) { printf ("A problem at kernel %d and iteration %d for actual value %f but expected value %f!\n", iKernel, i, outputDataR[i], fExpReduceResult[i]); break; } } } } // if ((iKernel % 2) == 1) // { // iLengthTotal = iLengthTotal / 2; // iSomething = iSomething * 2; // iGlobalWorkThing = iGlobalWorkThing / 2; // } } clReleaseMemObject(inputF); clReleaseMemObject(outputF); clReleaseMemObject(outputAll); // print the results // if (bPrint) // { // printf("output %d: \n", iGlobalSize); // for(i=0;i<iExpOutputSize; i++) // { // printf("%d - %f - %f\n", i, outputDataD[i], outputDataR[i]); // } // } // cleanup - release OpenCL resources free(inputDataF); free(outputDataD); free(outputDataR); GPAKShutdown(TheGPAK); GCAQShutdown (TheGCAQ); printf("%d - ", iGlobalSize); for (iKernel = 0; iKernel < iNoKernels; iKernel++) { printf("%f - ", (1.0 * TLPERS * iGlobalSize * iNoReps) / (MEGAHERTZ * timespecDiff(&(end[iKernel]), &(start[iKernel])))); } printf("\n"); return 0; }
/* * Main function */ int main(int argc, char** argv) { struct timespec start, stop; int next_option, verbose, write; const char* const short_options = "hvwi:b:t:o:"; char *text, *bin, *index, *output; clock_gettime(CLOCK_MONOTONIC, &start); program_name = argv[0]; const struct option long_options[] = { { "help", 0, NULL, 'h'}, { "verbose", 0, NULL, 'v'}, { "write", 0, NULL, 'w'}, { "text", 1, NULL, 't'}, { "bin", 1, NULL, 'b'}, { "index", 1, NULL, 'i'}, { "output", 1, NULL, 'o'}, { NULL, 0, NULL, 0} /* Required at end of array. */ }; write = verbose = 0; text = bin = index = output = NULL; do { next_option = getopt_long(argc, argv, short_options, long_options, NULL); switch (next_option) { case 'h': print_usage(stdout, 0); case 'v': verbose = 1; break; case 'w': write = 1; break; case 'o': output = (char *) malloc(sizeof (char) * (strlen(optarg) + 1)); strcpy(output, optarg); break; break; case 't': text = (char *) malloc(sizeof (char) * (strlen(optarg) + 1)); strcpy(text, optarg); break; case 'b': bin = (char *) malloc(sizeof (char) * (strlen(optarg) + 1)); strcpy(bin, optarg); break; case 'i': index = (char *) malloc(sizeof (char) * (strlen(optarg) + 1)); strcpy(index, optarg); break; } } while (next_option != -1); if (text == NULL) { fprintf(stdout, "Set the input text file\n"); print_usage(stdout, 1); } if (bin == NULL) { fprintf(stdout, "Set the output bin file\n"); print_usage(stdout, 1); } if (index == NULL) { fprintf(stdout, "Set the index file\n"); print_usage(stdout, 1); } if (write == 1) { writer(text, bin, index, verbose); } else { if (output == NULL) { fprintf(stdout, "Set the output file\n"); print_usage(stdout, 1); } createBTreeIndex(text, bin, index, output, verbose); } if (text) free(text); if (bin) free(bin); if (index) free(index); if (output) free(output); clock_gettime(CLOCK_MONOTONIC, &stop); printf("\n\tThe total time was %lu sec\n\n", timespecDiff(&stop, &start) / 1000000000); return (EXIT_SUCCESS); }
int main(int argc, char *argv[]) { struct timespec timeBase, timeNow; long long delta, deltaPrevious; int sockfd, sockfdClient, buffLen, readLen, readIdx, count, port; struct sockaddr_in addrServ, addrClient; socklen_t addrClientLen; char buff[2], *buffLong, label[21]; clock_gettime(CLOCKTYPE, &timeBase); port = SERVER_PORT; if (2 <= argc) { port = atoi(argv[1]); if (0 >= port) { port = SERVER_PORT; } } sockfd = socket(AF_INET, SOCK_STREAM, 0); if (0 > sockfd) { fprintf(stderr, "Error establishing socket.\n"); exit(1); } bzero((char *) &addrServ, sizeof(addrServ)); addrServ.sin_family = AF_INET; addrServ.sin_addr.s_addr = INADDR_ANY; addrServ.sin_port = htons(port); if (0 > bind(sockfd, (struct sockaddr *) &addrServ, sizeof(addrServ))) { fprintf(stderr, "Error binding socket to server port %d.\n", port); exit(1); } listen(sockfd, 5); printf("SERVER LISTENING ON PORT %d\n", port); fflush(stdout); // Enter loop accepting new connections for (count = 0;; count++) { addrClientLen = sizeof(addrClient); sockfdClient = accept(sockfd, (struct sockaddr *) &addrClient, &addrClientLen); if (0 > sockfdClient) { close(sockfd); fprintf(stderr, "Error accepting connection from port %d.\n", port); exit(1); } printf("NEW CONNECTION (%d)\n", count); fflush(stdout); deltaPrevious = -1; // Enter loop handling packets from this connection for (;;) { readLen = read(sockfdClient, buff, sizeof(buff)); if (0 == readLen) { break; } if (0 > readLen) { close(sockfdClient); close(sockfd); fprintf(stderr, "Error reading from connection on port %d.\n", port); exit(1); } #ifdef DEBUG printf("Read %d bytes\n", readLen); #endif buffLen = (unsigned int)buff[0] + 256 * (unsigned int)buff[1]; #ifdef DEBUG printf("Allocating %d bytes\n", buffLen); fflush(stdout); #endif buffLong = (char *) malloc((unsigned int)buffLen); if (NULL == buffLong) { close(sockfdClient); close(sockfd); fprintf(stderr, "Error allocating buffer for %d bytes.\n", buffLen); exit(1); } for (readIdx = 0; readIdx < buffLen; readIdx += readLen) { readLen = read(sockfdClient, buffLong + readIdx, buffLen - readIdx); if (0 == readLen) { break; } else if (0 > readLen) { close(sockfdClient); close(sockfd); fprintf(stderr, "Error reading from connection on port %d.\n", port); exit(1); } } if (0 == readLen) { break; } if (readIdx > sizeof(label) - 1) { readIdx = sizeof(label) - 1; } strncpy(label, buffLong, readIdx); label[readIdx] = 0; clock_gettime(CLOCKTYPE, &timeNow); delta = timespecDiff(&timeNow, &timeBase); if (-1 == deltaPrevious) { printf(":%d:%ld::%s:\n", count, (long)(delta / 1000000), label); } else { printf(":%d:%ld:%ld:%s:\n", count, (long)(delta / 1000000), (long)((delta - deltaPrevious) / 1000000), label); } fflush(stdout); deltaPrevious = delta; free(buffLong); } close(sockfdClient); printf("CONNECTION CLOSED (%d)\n", count); fflush(stdout); } close(sockfd); return 0; }