void create_and_write_diff_image(DiffRecord* drp, DiffMetricProc dmp, const int colorThreshold, const SkString& outputDir, const SkString& filename) { const int w = drp->fBase.fBitmap.width(); const int h = drp->fBase.fBitmap.height(); if (w != drp->fComparison.fBitmap.width() || h != drp->fComparison.fBitmap.height()) { drp->fResult = DiffRecord::kDifferentSizes_Result; } else { drp->fDifference.fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); drp->fDifference.fBitmap.allocPixels(); drp->fWhite.fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); drp->fWhite.fBitmap.allocPixels(); SkASSERT(DiffRecord::kUnknown_Result == drp->fResult); compute_diff(drp, dmp, colorThreshold); SkASSERT(DiffRecord::kUnknown_Result != drp->fResult); } if (outputDir.isEmpty()) { drp->fDifference.fStatus = DiffResource::kUnspecified_Status; drp->fWhite.fStatus = DiffResource::kUnspecified_Status; } else { drp->fDifference.fFilename = filename_to_diff_filename(filename); drp->fDifference.fFullPath = outputDir; drp->fDifference.fFullPath.append(drp->fDifference.fFilename); drp->fDifference.fStatus = DiffResource::kSpecified_Status; drp->fWhite.fFilename = filename_to_white_filename(filename); drp->fWhite.fFullPath = outputDir; drp->fWhite.fFullPath.append(drp->fWhite.fFilename); drp->fWhite.fStatus = DiffResource::kSpecified_Status; if (DiffRecord::kDifferentPixels_Result == drp->fResult) { if (write_bitmap(drp->fDifference.fFullPath, drp->fDifference.fBitmap)) { drp->fDifference.fStatus = DiffResource::kExists_Status; } else { drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status; } if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) { drp->fWhite.fStatus = DiffResource::kExists_Status; } else { drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status; } } } }
int main(int argc, char *argv[]) { /* default to UArray2 methods */ A2Methods_T methods = uarray2_methods_plain; assert(methods); /* default to best map */ A2Methods_mapfun *map = methods->map_default; assert(map); assert (argc <= 3); FILE *fp1, *fp2; Pnm_ppm image1, image2; fp1 = open_file(argc, argv[1]); fp2 = open_file(argc, argv[2]); image1 = Pnm_ppmread(fp1, methods); image2 = Pnm_ppmread(fp2, methods); if (!valid_dims(image1, image2)) { fprintf(stderr, "Invalid Dimensions\n"); fprintf(stdout, "1.0\n"); } else { compute_diff(image1, image2); } fclose(fp1); fclose(fp2); Pnm_ppmfree(&image1); Pnm_ppmfree(&image2); return 0; }
void do_parent(int child) { fd_set fds_read; struct timeval tv, start_time, end_time; int retval; /* Install signal handler for SIGUSR1 */ signal(SIGUSR1, catch_signal); /* Parent and child share an anonymous pipe. Select for read and wait for the timeout to occur. We wait for DO_PAUSE seconds. Let's see if that's approximately right.*/ FD_ZERO(&fds_read); FD_SET(fd_ap[0], &fds_read); tv.tv_sec = DO_PAUSE; tv.tv_usec = 0; (void) gettimeofday(&start_time, NULL); /* Record starting time */ retval = select(fd_ap[0]+1, &fds_read, NULL, NULL, &tv); (void) gettimeofday(&end_time, NULL); /* Record ending time */ /* Did we time out? */ if(retval != 0) e(1, "Should have timed out"); /* Approximately right? The standard does not specify how precise the timeout should be. Instead, the granularity is implementation-defined. In this test we assume that the difference should be no more than half a second.*/ if(compute_diff(start_time, end_time, DO_PAUSE) > DO_DELTA) e(2, "Time difference too large"); /* Let's wait for another DO_PAUSE seconds, expressed as microseconds */ FD_ZERO(&fds_read); FD_SET(fd_ap[0], &fds_read); tv.tv_sec = 0; tv.tv_usec = DO_PAUSE * 1000000L; (void) gettimeofday(&start_time, NULL); /* Record starting time */ retval = select(fd_ap[0]+1, &fds_read, NULL, NULL, &tv); (void) gettimeofday(&end_time, NULL); /* Record ending time */ if(retval != 0) e(3, "Should have timed out"); if(compute_diff(start_time, end_time, DO_PAUSE) > DO_DELTA) e(4, "Time difference too large"); /* Let's wait for another DO_PAUSE seconds, expressed in seconds and micro seconds. */ FD_ZERO(&fds_read); FD_SET(fd_ap[0], &fds_read); tv.tv_sec = DO_PAUSE - 1; tv.tv_usec = (DO_PAUSE - tv.tv_sec) * 1000000L; (void) gettimeofday(&start_time, NULL); /* Record starting time */ retval = select(fd_ap[0]+1, &fds_read, NULL, NULL, &tv); (void) gettimeofday(&end_time, NULL); /* Record ending time */ if(retval != 0) e(5, "Should have timed out"); if(compute_diff(start_time, end_time, DO_PAUSE) > DO_DELTA) e(6, "Time difference too large"); /* Finally, we test if our timeout is interrupted by a signal */ FD_ZERO(&fds_read); FD_SET(fd_ap[0], &fds_read); tv.tv_sec = DO_TIMEOUT; tv.tv_usec = 0; (void) gettimeofday(&start_time, NULL); /* Record starting time */ retval = select(fd_ap[0]+1, &fds_read, NULL, NULL, &tv); (void) gettimeofday(&end_time, NULL); /* Record ending time */ if(retval != -1) e(7, "Should have been interrupted"); if(compute_diff(start_time, end_time, DO_TIMEOUT) < DO_DELTA) e(8, "Failed to get interrupted by a signal"); if(!got_signal) e(9, "Failed to get interrupted by a signal"); waitpid(child, &retval, 0); exit(errct); }
void gl_loop() { static int i = 0; static int dir = 1; //////////// CL STUFF acquire_gl_tex(cl_tex_mem); // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); pthread_barrier_wait(&thread_barrier); // cl_int arg = i%STEPS; // err = clSetKernelArg(clkernelinfo.kernel,1,sizeof(cl_int),&arg); // if (error_cl(err, "clSetKernelArg 1")) // exit(1); // execute_cl(clkernelinfo); // ////////////////// Immediate mode textured quad // release_gl_tex(cl_tex_mem); pthread_barrier_wait(&thread_barrier); release_gl_tex(cl_tex_mem); glBindTexture(GL_TEXTURE_2D, gl_tex); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(1.0,1.0); glVertex2f(1.0,1.0); glTexCoord2f(1.0,0.0); glVertex2f(1.0,-1.0); glTexCoord2f(0.0,1.0); glVertex2f(-1.0,1.0); glTexCoord2f(0.0,0.0); glVertex2f(-1.0,-1.0); glEnd(); //////////////////////////////////////////// i += dir; if (!(i % (STEPS-1))){ dir *= -1; #ifdef __linux__ timespec _tp; clock_gettime(CLOCK_MONOTONIC, &_tp); double msec = compute_diff(tp, _tp); #elif defined _WIN32 __int64 _tp; _tp = snap_time(); double msec = compute_diff(tp,_tp); #endif std::cout << "Time elapsed: " << msec << " milliseconds " << "\t(" << int(STEPS / (msec/1000)) << " FPS) \r" ; std::flush(std::cout); tp = _tp; } glutSwapBuffers(); // std::cout << "Main thread reporting to barrier!" << std::endl; // pthread_barrier_wait(&thread_barrier); // std::cout << "Main thread exiting barrier!" << std::endl; }
int main( int argc, char** argv ) { int pnum, pid; double elapsed_time; float *A, *B, *C, *Cans; float diff; int n = 2048; int i, j, k; unsigned short seed[3]; if( argc != 1 ){ if( argc == 2 ){ n = atoi(argv[1]); } else{ printf("mmul [n]\n"); exit(0); } } MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &pnum); MPI_Comm_rank(MPI_COMM_WORLD, &pid); //printf("Processor %d out of %d says hi!\n", pid, pnum); if( pid == 0 ){ //printf("Intializing matrix size : %d x %d x %d\n", n, n, n); A = (float*)malloc( sizeof(float) * n * n ); B = (float*)malloc( sizeof(float) * n * n ); C = (float*)malloc( sizeof(float) * n * n ); seed[0] = 0; seed[1] = 1; seed[2] = 2; for (i=0; i<n; i++) { for (k=0; k<n; k++) { A(i,k) = (float)erand48(seed); } } for (k=0; k<n; k++) { for (j=0; j<n; j++) { B(k,j) = (float)erand48(seed); } } } MPI_Barrier(MPI_COMM_WORLD); elapsed_time = -1*MPI_Wtime(); //Please modify the content of this function mmul(A, B, C, n); MPI_Barrier(MPI_COMM_WORLD); elapsed_time += MPI_Wtime(); if( pid == 0 ){ printf("Elapsed Time : %f secs\n", elapsed_time); Cans = (float*)malloc( sizeof(float) * n * n ); mmul1(A, B, Cans, n); diff = compute_diff(C, Cans, n); printf("Performance : %.2f GFlops\n", 2.0*n*n*n/elapsed_time/1000000000 ); printf("Result Diff : %.3f\%\n", diff*100 ); free(A); free(B); free(C); free(Cans); }