这篇教程C++ timer_start函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中timer_start函数的典型用法代码示例。如果您正苦于以下问题:C++ timer_start函数的具体用法?C++ timer_start怎么用?C++ timer_start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了timer_start函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: func_randomcvoid func_randomc(void){ func_timer = &func_randomc_helper; timer_start();}
开发者ID:chsigi,项目名称:cube,代码行数:5,
示例2: mainint main(int argc, char *argv[]){ int num_threads; int vec_size; int custom_reduce_method; double accu; double time; double *vec; if (argc < 4) { printf("Usage: %s num_threads vec_size [reduce method]/n", argv[0]); printf(" - num_threads: number of threads to use for simulation, " "should be >=1/n"); printf(" - vec_size: size of the vector to do reduction on 10^n" "should be >=10/n"); printf(" - [reduce_method]: custom | sequential."); return EXIT_FAILURE; } num_threads = atoi(argv[1]); vec_size = pow(10, atoi(argv[2])); if (num_threads < 1) { printf("argument error: num_threads should be >=1./n"); return EXIT_FAILURE; } if (vec_size < 4) { printf("argument error: vec_size should be >=4./n"); return EXIT_FAILURE; } if (strcmp(argv[3], "sequential") == 0) { custom_reduce_method = 0; } else { custom_reduce_method = 1; } vec = (double*)malloc(vec_size * sizeof(double)); /* Fill a vector with a sinus values */ #pragma omp parallel for for (int i = 0; i < vec_size; i++) { vec[i] = sin(i); } omp_set_num_threads(num_threads); /* Start timing the effeciency of openMP */ timer_start(); /* Calculate a reduced vector with openMP */ if (custom_reduce_method) { accu = reduce2(fun, vec, vec_size, 0); /* accu = sum(vec, vec_size); */ } else { accu = reduce(fun, vec, vec_size, 0); } /* Stop timing */ time = timer_end(); printf("%d, %d, %g/n",num_threads, vec_size, time); free(vec); vec = NULL; return EXIT_SUCCESS;}
开发者ID:MaicoTimmerman,项目名称:uva_concurrency_parallel_programming,代码行数:69,
示例3: dimension//.........这里部分代码省略......... #ifdef ENABLE_DEBUG printf("--------------------------------------------------------------/n"); printf(" warning matrix too small N=%d NB=%d, calling lapack on CPU /n", (int) n, (int) nb); printf("--------------------------------------------------------------/n"); #endif lapackf77_dsyevd(jobz_, uplo_, &n, A, &lda, w, work, &lwork, iwork, &liwork, info); return *info; } /* Get machine constants. */ safmin = lapackf77_dlamch("Safe minimum"); eps = lapackf77_dlamch("Precision"); smlnum = safmin / eps; bignum = 1. / smlnum; rmin = magma_dsqrt(smlnum); rmax = magma_dsqrt(bignum); /* Scale matrix to allowable range, if necessary. */ anrm = lapackf77_dlansy("M", uplo_, &n, A, &lda, work ); iscale = 0; if (anrm > 0. && anrm < rmin) { iscale = 1; sigma = rmin / anrm; } else if (anrm > rmax) { iscale = 1; sigma = rmax / anrm; } if (iscale == 1) { lapackf77_dlascl(uplo_, &izero, &izero, &d_one, &sigma, &n, &n, A, &lda, info); } /* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */ // dsytrd work: e (n) + tau (n) + llwork (n*nb) ==> 2n + n*nb // dstedx work: e (n) + tau (n) + z (n*n) + llwrk2 (1 + 4*n + n^2) ==> 1 + 6n + 2n^2 inde = 0; indtau = inde + n; indwrk = indtau + n; indwk2 = indwrk + n*n; llwork = lwork - indwrk; llwrk2 = lwork - indwk2; magma_timer_t time=0; timer_start( time ); magma_dsytrd(uplo, n, A, lda, w, &work[inde], &work[indtau], &work[indwrk], llwork, &iinfo); timer_stop( time ); timer_printf( "time dsytrd = %6.2f/n", time ); /* For eigenvalues only, call DSTERF. For eigenvectors, first call DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the tridiagonal matrix, then call DORMTR to multiply it to the Householder transformations represented as Householder vectors in A. */ if (! wantz) { lapackf77_dsterf(&n, w, &work[inde], info); } else { timer_start( time ); if (MAGMA_SUCCESS != magma_dmalloc( &dwork, 3*n*(n/2 + 1) )) { *info = MAGMA_ERR_DEVICE_ALLOC; return *info; } // TTT Possible bug for n < 128 magma_dstedx(MagmaRangeAll, n, 0., 0., 0, 0, w, &work[inde], &work[indwrk], n, &work[indwk2], llwrk2, iwork, liwork, dwork, info); magma_free( dwork ); timer_stop( time ); timer_printf( "time dstedx = %6.2f/n", time ); timer_start( time ); magma_dormtr(MagmaLeft, uplo, MagmaNoTrans, n, n, A, lda, &work[indtau], &work[indwrk], n, &work[indwk2], llwrk2, &iinfo); lapackf77_dlacpy("A", &n, &n, &work[indwrk], &n, A, &lda); timer_stop( time ); timer_printf( "time dormtr + copy = %6.2f/n", time ); } /* If matrix was scaled, then rescale eigenvalues appropriately. */ if (iscale == 1) { d__1 = 1. / sigma; blasf77_dscal(&n, &d__1, w, &ione); } work[0] = lwmin * one_eps; // round up iwork[0] = liwmin; return *info;} /* magma_dsyevd */
开发者ID:cjy7117,项目名称:DVFS-MAGMA,代码行数:101,
示例4: elements/***************************************************************************//** Purpose ------- SGETRF_m computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges. This version does not require work space on the GPU passed as input. GPU memory is allocated in the routine. The matrix may exceed the GPU memory. The factorization has the form A = P * L * U where P is a permutation matrix, L is lower triangular with unit diagonal elements (lower trapezoidal if m > n), and U is upper triangular (upper trapezoidal if m < n). This is the right-looking Level 3 BLAS version of the algorithm. Note: The factorization of big panel is done calling multiple-gpu-interface. Pivots are applied on GPU within the big panel. Arguments --------- @param[in] ngpu INTEGER Number of GPUs to use. ngpu > 0. @param[in] m INTEGER The number of rows of the matrix A. M >= 0. @param[in] n INTEGER The number of columns of the matrix A. N >= 0. @param[in,out] A REAL array, dimension (LDA,N) On entry, the M-by-N matrix to be factored. On exit, the factors L and U from the factorization A = P*L*U; the unit diagonal elements of L are not stored. /n Higher performance is achieved if A is in pinned memory, e.g. allocated using magma_malloc_pinned. @param[in] lda INTEGER The leading dimension of the array A. LDA >= max(1,M). @param[out] ipiv INTEGER array, dimension (min(M,N)) The pivot indices; for 1 <= i <= min(M,N), row i of the matrix was interchanged with row IPIV(i). @param[out] info INTEGER - = 0: successful exit - < 0: if INFO = -i, the i-th argument had an illegal value or another error occured, such as memory allocation failed. - > 0: if INFO = i, U(i,i) is exactly zero. The factorization has been completed, but the factor U is exactly singular, and division by zero will occur if it is used to solve a system of equations. @ingroup magma_getrf*******************************************************************************/extern "C" magma_int_tmagma_sgetrf_m( magma_int_t ngpu, magma_int_t m, magma_int_t n, float *A, magma_int_t lda, magma_int_t *ipiv, magma_int_t *info){#define A(i,j) (A + (j)*lda + (i))#define dAT(d,i,j) (dAT[d] + (i)*nb*ldn_local + (j)*nb)#define dPT(d,i,j) (dPT[d] + (i)*nb*nb + (j)*nb*maxm) magma_timer_t time=0, time_total=0, time_alloc=0, time_set=0, time_get=0, time_comp=0; timer_start( time_total ); //real_Double_t flops; float c_one = MAGMA_S_ONE; float c_neg_one = MAGMA_S_NEG_ONE; float *dAT[MagmaMaxGPUs], *dA[MagmaMaxGPUs], *dPT[MagmaMaxGPUs]; magma_int_t iinfo = 0, nb, nbi, maxm, n_local[MagmaMaxGPUs], ldn_local; magma_int_t N, M, NB, NBk, I, d, ngpu0 = ngpu; magma_int_t ii, jj, h, offset, ib, rows; magma_queue_t queues[MagmaMaxGPUs][2]; magma_event_t event[MagmaMaxGPUs][2]; *info = 0; if (m < 0) *info = -1; else if (n < 0) *info = -2; else if (lda < max(1,m)) *info = -4; if (*info != 0) { magma_xerbla( __func__, -(*info) ); return *info; }//.........这里部分代码省略.........
开发者ID:maxhutch,项目名称:magma,代码行数:101,
示例5: mainint main(int argc, char * argv[]) { system("clear"); signal(SIGINT, interrupt); ipv4_addr_t multiaddress; ipv4_str_addr (RIP_MULTICAST_IPv4, multiaddress); if(argc == 2) { if( !strcmp(argv[1], "--verbose")) { is_verbose = 1; print_warning("(Debug mode ON) /n"); } } else printf("(Run with --verbose to print more info)/n"); bold ("Starting RIP Server... /t/t/t/t/t"); print_success("[ OK ]/n"); table = rip_table_create (); if (initialize_rip (table, RIP_PORT) == -1) { /* Already printed advert inside function */ return -1; } int K = rip_route_table_read ( RIP_TABLE_TXT, table ); /* set inf timer to routes read from file */ int k; for( k = 0; k < K; k++ ) { timerms_reset(&table->routes[k]->time, INFINITE_TIMER); } rip_table_t * table_aux; ipv4_addr_t src; long int r = random_number(-15, 15)*1000;//SEND UNSOLICITED RESPONSE MESSAGES EVERY 30 SECONDS +- 15s timerms_t update_timer = timer_start ( UPDATE_TIME + r );//SEND REQUEST TO FILL ROUTE TABLE rip_route_table_print ( table ); for ( ;; ) { if (timer_ended (update_timer)) { /* Si se ha acabado el update timer */ send_rip_response (multiaddress, message_ptr, table, RIP_PORT); r = random_number(-15, 15)*1000; if ( is_verbose ) printf("(update_time set to %ld)/n", r +UPDATE_TIME); update_timer = timer_start (UPDATE_TIME + r); bold ("/nCurrent table:/n"); rip_route_table_print ( table ); } int src_port; int bytes_received = rip_recv (src, message_ptr, MIN_TIMER, &src_port);//WE RECEIVE A MESSAGE if (bytes_received>0) { //WE CONVERT THE MESSAGE TO A ROUTE TABLE FORMAT table_aux = convert_message_table (message_ptr, rip_number_entries(bytes_received)); if ( is_verbose ) { print_notice ("/nReceived packet/n"); print_packet (message_ptr, rip_number_entries(bytes_received)); }//IF THE MESSAGE IS A RESPONSE... if (message_ptr->command == 2) { //VALIDATE (HAY QUE IMPLEMENTARLO) //number of entries in the received message int num_entries = rip_number_entries (bytes_received); int trig_update_flag = 0; //by default, when receiving, do not send update //AND THIS IS WHERE THE MAGIC HAPPENS, WE PROCESS THE RESPONSE MESSAGE trig_update_flag = compare_tables (table, table_aux, num_entries, src); if (trig_update_flag) { send_rip_response (multiaddress, message_ptr, table, RIP_PORT); } bold ("/nCurrent table:/n"); rip_route_table_print ( table ); } if (message_ptr->command == 1 &&//.........这里部分代码省略.........
开发者ID:jsdario,项目名称:rysca,代码行数:101,
示例6: elements//.........这里部分代码省略......... magmablasGetKernelStream( &orig_stream ); /* Use hybrid blocked code. */ maxm = ((m + block_size-1)/block_size)*block_size; /* some initializations */ for (d=0; d < ngpu; d++) { magma_setdevice(d); n_local[d] = ((n/nb)/ngpu)*nb; if (d < (n/nb) % ngpu) n_local[d] += nb; else if (d == (n/nb) % ngpu) n_local[d] += n % nb; /* workspaces */ d_panel[d] = &(d_lAP[d][h*nb*maxm]); /* temporary panel storage */ } trace_init( 1, ngpu, 2, (CUstream_st**)queues ); /* start sending the panel to cpu */ nb0 = min(mindim, nb); magma_setdevice(0); magmablasSetKernelStream(queues[0][1]); trace_gpu_start( 0, 1, "comm", "get" ); magmablas_ztranspose( nb0, m, dAT(0,0,0), lddat, d_lAP[0], maxm ); magma_zgetmatrix_async( m, nb0, d_lAP[0], maxm, W(0), ldw, queues[0][1] ); trace_gpu_end( 0, 1 ); /* ------------------------------------------------------------------------------------- */ magma_timer_t time=0; timer_start( time ); s = mindim / nb; for( j=0; j < s; j++ ) { /* Set the GPU number that holds the current panel */ id = j % ngpu; magma_setdevice(id); /* Set the local index where the current panel is */ j_local = j/ngpu; cols = maxm - j*nb; rows = m - j*nb; /* synchronize j-th panel from id-th gpu into work */ magma_queue_sync( queues[id][1] ); /* j-th panel factorization */ trace_cpu_start( 0, "getrf", "getrf" ); lapackf77_zgetrf( &rows, &nb, W(j), &ldw, ipiv+j*nb, &iinfo); if ( (*info == 0) && (iinfo > 0) ) { *info = iinfo + j*nb; } trace_cpu_end( 0 ); /* start sending the panel to all the gpus */ d = (j+1) % ngpu; for( dd=0; dd < ngpu; dd++ ) { magma_setdevice(d); trace_gpu_start( 0, 1, "comm", "set" ); magma_zsetmatrix_async( rows, nb, W(j), ldw, &d_lAP[d][(j%h)*nb*maxm], cols, queues[d][1] );
开发者ID:cjy7117,项目名称:FT-MAGMA,代码行数:67,
示例7: mainint main(void) { #define NMAX 100 //array size for storing the values of I_n int nminn = 0; //min value of n to be calulated for integrals int nmaxx = 100; //max value of n to be calculated for integrals double vals1[NMAX + 1], vals2[NMAX + 1]; integral_recur (nminn, nmaxx, vals1); integral_gen (nminn, nmaxx, vals2); // prints and compares the values of the different methods for(int i = 0,j = nminn; i <= nmaxx - nminn; i++,j++) { printf("%.18f/t%.18f/t%d/n", vals1[i], vals2[i], j); } int count = 10; double time; double time1; double tmin = 1; double tmax = 2; // times integral_recur and integral_gen per function call // adjusts the number of calls such that there are enough calls to get a good // average time per function call printf("integral_recur/n"); do { timer_start (); for (int k = 0; k <= count; k++) { integral_recur (nminn, nmaxx, vals1); } time = timer_stop (); time1 = time / count; printf (" %10.2f usec %10.6f sec %10d/n", time1 * 1.e6, time, count); /* * adjust count such that cpu time is between * tmin and tmax */ count = adjust_rep_count (count, time, tmin, tmax); } while ((time > tmax) || (time < tmin)); printf("integral_gen/n"); count = 10; do { timer_start (); for (int k = 0; k <= count; k++) { integral_gen (nminn, nmaxx, vals2); } time = timer_stop (); time1 = time / count; printf (" %10.2f usec %10.6f sec %10d/n", time1 * 1.e6, time, count); /* * adjust count such that cpu time is between * tmin and tmax */ count = adjust_rep_count (count, time, tmin, tmax); } while ((time > tmax) || (time < tmin)); return 0;}
开发者ID:Duderichy,项目名称:hw07,代码行数:87,
示例8: copy_faces//---------------------------------------------------------------------// this function copies the face values of a variable defined on a set // of cells to the overlap locations of the adjacent sets of cells. // Because a set of cells interfaces in each direction with exactly one // other set, we only need to fill six different buffers. We could try to // overlap communication with computation, by computing// some internal values while communicating boundary values, but this// adds so much overhead that it's not clearly useful. //---------------------------------------------------------------------void copy_faces(){ int c, i; cl_int ecode = 0; //--------------------------------------------------------------------- // exit immediately if there are no faces to be copied //--------------------------------------------------------------------- if (num_devices == 1) { compute_rhs(); return; } //--------------------------------------------------------------------- // because the difference stencil for the diagonalized scheme is // orthogonal, we do not have to perform the staged copying of faces, // but can send all face information simultaneously to the neighboring // cells in all directions //--------------------------------------------------------------------- if (timeron) timer_start(t_bpack); for (c = 0; c < ncells; c++) { for (i = 0; i < num_devices; i++) { ecode = clEnqueueNDRangeKernel(cmd_queue[i * 2], k_copy_faces1[i][c], COPY_FACES1_DIM, NULL, copy_faces1_gw[i][c], copy_faces1_lw[i][c], 0, NULL, NULL); clu_CheckError(ecode, "clEnqueueNDRange() for copy_faces1"); } for (i = 0; i < num_devices; i++) { ecode = clEnqueueNDRangeKernel(cmd_queue[i * 2], k_copy_faces2[i][c], COPY_FACES2_DIM, NULL, copy_faces2_gw[i][c], copy_faces2_lw[i][c], 0, NULL, NULL); clu_CheckError(ecode, "clEnqueueNDRange() for copy_faces2"); ecode = clEnqueueNDRangeKernel(cmd_queue[i * 2], k_copy_faces3[i][c], COPY_FACES3_DIM, NULL, copy_faces3_gw[i][c], copy_faces3_lw[i][c], 0, NULL, NULL); clu_CheckError(ecode, "clEnqueueNDRange() for copy_faces3"); } for (i = 0; i < num_devices; i++) { CHECK_FINISH(i * 2); } } if (timeron) timer_stop(t_bpack); if (timeron) timer_start(t_exch); for (i = 0; i < num_devices; i++) { CHECK_FINISH(i * 2); ecode = clEnqueueCopyBuffer(cmd_queue[successor[i][0] * 2 + 1], m_out_buffer[i], m_in_buffer[successor[i][0]], start_send_east[i]*sizeof(double), start_recv_west[successor[i][0]]*sizeof(double), east_size[i]*sizeof(double), 0, NULL, NULL); CHECK_FINISH(successor[i][0] * 2 + 1); } for (i = 0; i < num_devices; i++) { ecode = clEnqueueCopyBuffer(cmd_queue[predecessor[i][0] * 2 + 1], m_out_buffer[i], m_in_buffer[predecessor[i][0]], start_send_west[i]*sizeof(double), start_recv_east[predecessor[i][0]]*sizeof(double), west_size[i]*sizeof(double), 0, NULL, NULL); CHECK_FINISH(predecessor[i][0] * 2 + 1); ecode = clEnqueueCopyBuffer(cmd_queue[successor[i][1] * 2 + 1], m_out_buffer[i], m_in_buffer[successor[i][1]], start_send_north[i]*sizeof(double), start_recv_south[successor[i][1]]*sizeof(double), north_size[i]*sizeof(double), 0, NULL, NULL); CHECK_FINISH(successor[i][1] * 2 + 1);//.........这里部分代码省略.........
开发者ID:ashwinma,项目名称:multicl,代码行数:101,
示例9: recive_udp_datavoid * recive_udp_data(void * parameters){ struct timerInfo timeOut[MAX_PLAYERS]; int i; char buffer[128]; struct stcInfo moveInfo; struct playerInfo * player = (struct playerInfo*) parameters; //Init the timer for (i = 0; i < MAX_PLAYERS; i++) { timer_init(&timeOut[i]); } while (1) { recvfrom(udpInfo.udpSd, buffer, sizeof(buffer), 0, udpInfo.serverIp, sizeof(udpInfo.serverIp)); //printf("recived from server: %s /n", buffer); sscanf(buffer, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &moveInfo.team,&moveInfo.x, &moveInfo.y , &moveInfo.player, &moveInfo.mouseX, &moveInfo.mouseY,&moveInfo.fire, &moveInfo.bulletX, &moveInfo.bulletY, &moveInfo.tankAngle, &moveInfo.cannonAngle, &moveInfo.dead, &moveInfo.healthPoints, &moveInfo.redPoints, &moveInfo.bluePoints); timer_start(&timeOut[moveInfo.player]); //Saves the incoming data in the players struct. player[moveInfo.player].slot = moveInfo.player; player[moveInfo.player].team = moveInfo.team; player[moveInfo.player].xCord = moveInfo.x; player[moveInfo.player].yCord = moveInfo.y; player[moveInfo.player].mouseX = moveInfo.mouseX; player[moveInfo.player].mouseY = moveInfo.mouseY; player[moveInfo.player].bulletX = moveInfo.bulletX; player[moveInfo.player].bulletY = moveInfo.bulletY; player[moveInfo.player].fire = moveInfo.fire; player[moveInfo.player].tankAngle = -1*moveInfo.tankAngle; player[moveInfo.player].cannonAngle = -1*moveInfo.cannonAngle; player[moveInfo.player].healthPoints = moveInfo.healthPoints; player[moveInfo.player].dead = moveInfo.dead; player[moveInfo.player].connected = 1; redPoints = moveInfo.redPoints; bluePoints = moveInfo.bluePoints; //If no new udp from a client it disconnects after 0.5 sec for (i = 0; i < MAX_PLAYERS; i++) { if (timer_get_ticks(&timeOut[i]) > 500) { player[i].connected = 0; timer_stop(&timeOut[i]); } } sleep(0); } }
开发者ID:Urbansson,项目名称:Epic-Tank-Battle,代码行数:69,
示例10: mainint main(int argc, char ** argv) { // enhanced usage, useful for testing if (argc != 1 && argc != 2 && argc != 7) { fprintf(stderr, "Usage: %s [[threads] yMin yMax xMin xMax dxy]/n", argv[0]); fprintf(stderr, "Either specify no args, or only threads, or all args./n"); return -2; } // determine amount of threads if (argc > 1) omp_set_num_threads(atoi(argv[1])); else omp_set_num_threads(4); // set constants if supplied if (argc == 7) { yMin = atof(argv[2]); yMax = atof(argv[3]); xMin = atof(argv[4]); xMax = atof(argv[5]); dxy = atof(argv[6]); } double time; timer_start(); double cx, cy; double zx, zy, new_zx; unsigned char n; int nx, ny; // The Mandelbrot calculation is to iterate the equation // z = z*z + c, where z and c are complex numbers, z is initially // zero, and c is the coordinate of the point being tested. If // the magnitude of z remains less than 2 for ever, then the point // c is in the Mandelbrot set. We write out the number of iterations // before the magnitude of z exceeds 2, or UCHAR_MAX, whichever is // smaller. nx = 0; ny = 0; nx = (xMax - xMin) / dxy; ny = (yMax - yMin) / dxy; int i, j; unsigned char * buffer = malloc(nx * ny * sizeof(unsigned char)); if (buffer == NULL) { fprintf (stderr, "Couldn't malloc buffer!/n"); return EXIT_FAILURE; } // do the calculations parallel #pragma omp parallel for private(i, j, cx, zx, zy, n, new_zx, cy) for (i = 0; i < ny; i++) { cy = yMin - dxy + i * dxy; for (j = 0; j < nx; j++) { cx = xMin - dxy + j * dxy; zx = 0.0; zy = 0.0; n = 0; while ((zx*zx + zy*zy < 4.0) && (n != UCHAR_MAX)) { new_zx = zx*zx - zy*zy + cx; zy = 2.0*zx*zy + cy; zx = new_zx; n++; } buffer[i * nx + j] = n; } } time = timer_end(); fprintf (stderr, "Took %g seconds./nNow writing file.../n", time); fwrite(buffer, sizeof(unsigned char), nx * ny, stdout); fprintf (stderr, "All done! To process the image: convert -depth 8 -size " / "%dx%d gray:output out.jpg/n", nx, ny); return 0;}
开发者ID:bwitzen,项目名称:concurrency,代码行数:81,
示例11: loop_playbool loop_play( boardsPBN * bop, playTracesPBN * playsp, solvedPlays * solvedplp, dealPBN * deal_list, playTracePBN * play_list, solvedPlay * trace_list, int number){#ifdef BATCHTIMES printf("%8s %24s/n", "Hand no.", "Time");#endif for (int i = 0; i < number; i += input_number) { int count = (i + input_number > number ? number - i : input_number); bop->noOfBoards = count; playsp->noOfBoards = count; for (int j = 0; j < count; j++) { bop->deals[j] = deal_list[i + j]; bop->target[j] = 0; bop->solutions[j] = 3; bop->mode[j] = 1; playsp->plays[j] = play_list[i + j]; } timer_start(); int ret; if ((ret = AnalyseAllPlaysPBN(bop, playsp, solvedplp, 1)) != RETURN_NO_FAULT) { printf("loop_play i %i: Return %d/n", i, ret); exit(0); } tu = timer_end();#ifdef BATCHTIMES printf("%8d (%5.1f%%) %15d/n", i + count, 100. * (i + count) / static_cast<double>(number), tu); fflush(stdout);#endif for (int j = 0; j < count; j++) { if (! compare_TRACE(&solvedplp->solved[j], &trace_list[i + j])) { printf("loop_play i %d, j %d: Difference/n", i, j); // printf("trace_list[%d]: /n", i+j); // print_TRACE(&trace_list[i+j]); // printf("solvedplp[%d]: /n", j); // print_TRACE(&solvedplp->solved[j]); } } }#ifdef BATCHTIMES printf("/n");#endif return true;}
开发者ID:jdh8,项目名称:dds,代码行数:67,
示例12: interval//.........这里部分代码省略......... return *info; } /* If matrix is very small, then just call LAPACK on CPU, no need for GPU */ if (n <= 128) { lapackf77_dsygvd( &itype, jobz_, uplo_, &n, A, &lda, B, &ldb, w, work, &lwork, iwork, &liwork, info ); *mout = n; return *info; } if (MAGMA_SUCCESS != magma_dmalloc( &dA, n*ldda ) || MAGMA_SUCCESS != magma_dmalloc( &dB, n*lddb )) { magma_free( dA ); magma_free( dB ); *info = MAGMA_ERR_DEVICE_ALLOC; return *info; } magma_queue_t queue; magma_device_t cdev; magma_getdevice( &cdev ); magma_queue_create( cdev, &queue ); /* Form a Cholesky factorization of B. */ magma_dsetmatrix( n, n, B, ldb, dB, lddb, queue ); magma_dsetmatrix_async( n, n, A, lda, dA, ldda, queue ); magma_timer_t time=0; timer_start( time ); magma_dpotrf_gpu( uplo, n, dB, lddb, info ); if (*info != 0) { *info = n + *info; return *info; } timer_stop( time ); timer_printf( "time dpotrf_gpu = %6.2f/n", time ); magma_queue_sync( queue ); magma_dgetmatrix_async( n, n, dB, lddb, B, ldb, queue ); timer_start( time ); /* Transform problem to standard eigenvalue problem and solve. */ magma_dsygst_gpu( itype, uplo, n, dA, ldda, dB, lddb, info ); timer_stop( time ); timer_printf( "time dsygst_gpu = %6.2f/n", time ); /* simple fix to be able to run bigger size. * set dB=NULL so we know to re-allocate below * TODO: have dwork here that will be used as dB and then passed to dsyevd. */ if (n > 5000) { magma_queue_sync( queue ); magma_free( dB ); dB=NULL; }
开发者ID:xulunfan,项目名称:magma,代码行数:66,
示例13: uniform/*c This is the serial version of the APP Benchmark 1,c the "embarassingly parallel" benchmark.cc M is the Log_2 of the number of complex pairs of uniform (0, 1) randomc numbers. MK is the Log_2 of the size of each batch of uniform randomc numbers. MK can be set for convenience on a given system, since it doesc not affect the results.*/int main(int argc, char **argv) { double *x, **xx, *q, **qq; double Mops, t1, t2, t3, t4, x1, x2, sx, sy, tm, an, tt, gc; double dum[3] = { 1.0, 1.0, 1.0 }; const int TRANSFER_X = 1; int np, nn, ierr, node, no_nodes, i, l, k, nit, ierrcode, no_large_nodes, np_add, k_offset, j; double loc_x,loc_t1,loc_t2,loc_t3,loc_t4; double loc_a1,loc_a2,loc_x1,loc_x2,loc_z; boolean verified; char size[13+1]; /* character*13 */ /* Allocate working memory */ x = (double*) malloc(sizeof(double) * 2*NK); xx = (double**) malloc(sizeof(double*) * NN); xx[0] = (double*) malloc(sizeof(double) * NN * 2*NK); for (i = 1; i < NN; i++) xx[i] = xx[i-1] + (2*NK); q = (double*) malloc(sizeof(double) * NQ); qq = (double**) malloc(sizeof(double*) * NN); qq[0] = (double*) malloc(sizeof(double) * NN * NQ); for (i = 1; i < NN; i++) qq[i] = qq[i-1] + NQ;/*c Because the size of the problem is too large to store in a 32-bitc integer for some classes, we put it into a string (for printing).c Have to strip off the decimal point put in there by the floatingc point print statement (internal file)*/ printf("/n/n NAS Parallel Benchmarks 2.3 OpenACC C version" " - EP Benchmark/n"); sprintf(size, "%12.0f", pow(2.0, M+1)); for (j = 13; j >= 1; j--) { if (size[j] == '.') size[j] = ' '; } printf(" Number of random numbers generated: %13s/n", size); verified = FALSE;/*c Compute the number of "batches" of random number pairs generated c per processor. Adjust if the number of processors does not evenly c divide the total number*/ np = NN;/*c Call the random number generator functions and initializec the x-array to reduce the effects of paging on the timings.c Also, call all mathematical functions that are used. Makec sure these initializations cannot be eliminated as dead code.*/#pragma acc data create(qq[0:NN][0:NQ],x[0:2*NK],xx[0:NN][0:2*NK]) / copyout(q[0:NQ]){ vranlc(0, &(dum[0]), dum[1], &(dum[2])); dum[0] = randlc(&(dum[1]), dum[2]); for (i = 0; i < 2*NK; i++) x[i] = -1.0e99; Mops = log(sqrt(fabs(max(1.0, 1.0)))); timer_clear(1); timer_clear(2); timer_clear(3); timer_start(1); vranlc(0, &t1, A, x); #pragma acc update device(x[0:2*NK])/* Compute AN = A ^ (2 * NK) (mod 2^46). */ t1 = A; for ( i = 1; i <= MK+1; i++) { t2 = randlc(&t1, t1); } an = t1; tt = S; gc = 0.0; sx = 0.0; sy = 0.0; #pragma acc parallel loop for (k = 0; k < np; k++) { /* Initialize private q (qq) */ #pragma acc loop for (i = 0; i < NQ; i++) qq[k][i] = 0.0;//.........这里部分代码省略.........
开发者ID:4m1g0,项目名称:NPB2.3-OpenACC-C,代码行数:101,
示例14: mainint main(int argc, char *argv[]){ double err = 0.0; struct timeval start; float time = 0.0; int n; nr_nodes = get_nr_nodes(); initial_node = get_node_id () ; next_node = (initial_node + 1) % nr_nodes ; nr_migrations = nr_nodes + 1 ; parse_args(argc, argv); if (verbose>=2) { printf("gram-schmidt 'uni-proc' for %dx%d in", numcols, numrows); fflush(stdout); } time = 0 ; for (n=0 ; n<numloops ; n++) { mat_init(&mat); timer_start(&start); up_mgs(&mat); time += timer_stop(&start); if (verbose > 2) printf ("up_gs finished, starting orth_err/n"); if (migration == 1 && get_node_id() != initial_node) migrate_self (initial_node); err = orth_err(&mat); printf ("/n Err = %g/n", err); if ( err < ERROR ) printf ("-- MGS test : PASSED --/n/n/n"); else { printf ("-- MGS test : FAILED --/n/n/n"); exit(-1) ; } } /* migration ici = pb */ if (verbose>2) printf ("up-gs : terminé/n"); if (verbose >= 1) { printf("/ntime :"); printf(" %g s (err: %g)/n", time/(float)numloops, err); } if (save_matrix) save_normalized_matrix(); if (verbose>2) printf ("up_gs termine/n"); return 0;}
开发者ID:bcopos,项目名称:android_cluster,代码行数:65,
示例15: main//.........这里部分代码省略......... printf("/n/n"); radixsort(test_array, N_ITEMS, sizeof(test_item_t), get_value, 10); printf("array after radixsort/n = "); print_array(test_array, N_ITEMS); printf("/n/n"); /* Now test heapsort. */ memcpy(test_array, a, sizeof(test_array)); printf("array before heapsort/n = "); print_array(test_array, N_ITEMS); printf("/n/n"); heapsort(test_array, N_ITEMS, sizeof(test_item_t), item_cmp); printf("array after heapsort/n = "); print_array(test_array, N_ITEMS); printf("/n/n"); /* Time the quicksort and mergesort sorting functions. */ printf("Enter the number of samples to use: "); scanf("%d", &n_samples); printf("Enter the maximum array length to sort: "); scanf("%d", &max_n); printf("Enter the step size for array lengths: "); scanf("%d", &step_n); t = timing_alloc(5); /* Five different sorting algorithms. */ printf("/nResults (n, qsort, quicksort, mergesort, mergesort0, heapsort) (msec)/n" ); for(i = step_n; i <= max_n; i += step_n) { array_size = i * sizeof(test_item_t); timing_array = malloc(array_size); copy_array = malloc(array_size); rand_array(copy_array, i, MAX_VALUE); timing_reset(t); for(j = 0; j < n_samples; j++) { memcpy(timing_array, copy_array, array_size); timing_start(); qsort(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,0); memcpy(timing_array, copy_array, array_size); timing_start(); quicksort(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,1); memcpy(timing_array, copy_array, array_size); timing_start(); mergesort(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,2); memcpy(timing_array, copy_array, array_size); timing_start(); mergesort0(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,3); memcpy(timing_array, copy_array, array_size); timing_start(); heapsort(timing_array, i, sizeof(test_item_t), item_cmp); timing_stop(t,4); } printf("%d", i); timing_print(t,"/t%.2f",n_samples); putchar('/n'); free(timing_array); free(copy_array); } timing_free(t); /* Time radix sort on the largest array, using different radix sizes. */ printf("/nRadix Sort Results. Using n = %d/n", max_n); printf("(radix, time)/n"); array_size = max_n * sizeof(test_item_t); timing_array = malloc(array_size); copy_array = malloc(array_size); rand_array(copy_array, max_n, MAX_VALUE); for(radix = 2; radix <= max_n; radix <<= 1) { timer_reset(); for(j = 0; j < n_samples; j++) { memcpy(timing_array, copy_array, array_size); timer_start(); radixsort(timing_array, max_n, sizeof(test_item_t), get_value, radix); timer_stop(); } printf("%d", radix); timer_print("/t%.2f", n_samples); putchar('/n'); } free(timing_array); free(copy_array); return 0;}
开发者ID:nickleefly,项目名称:experiment,代码行数:101,
示例16: main//.........这里部分代码省略......... //Makes the connection to the server if(!(init_udp_tcp(&udpSd, &tcpSd, argv[1], argv[2]))) { printf("Error making connection/n"); return 0; } //load the images (Function maybe) blueTank = load_image( "./images/blueTank.bmp" ); blueCannon = load_image( "./images/blueCannon.bmp" ); redTank = load_image( "./images/redTank.bmp" ); redCannon = load_image( "./images/redCannon.bmp" ); worldMap = load_image( "./images/worldMap.bmp" ); bullet = load_image( "./images/bullet.bmp" ); //Load the fonts font = TTF_OpenFont( "./fonts/Army.ttf", 24 ); reloadFont = TTF_OpenFont( "./fonts/Armyfat.ttf", 24 ); //Moves udp info to global var udpInfo.udpSd = udpSd; strcpy(udpInfo.serverIp, argv[1]); //Recives the first information from the server recv(tcpSd, buffer, sizeof(buffer), 0); myId = atoi(buffer); //Starts the Recive data thread pthread_create( &reciveUdpData, NULL, recive_udp_data, &(player)); while (run) { //Start the timer timer_start(&fps); while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE) { run = FALSE; } handel_input(&event, tcpSd ); } camera.xCord = -player[myId].xCord; camera.yCord = -player[myId].yCord; //From here we draw stuff on the screen SDL_FillRect(screen,NULL, 0x000000); //Draws WorldMAps draw_map(player[myId].xCord,player[myId].yCord, worldMap, screen); //DISPLAYES YOUR TANK+++++++++++++++++++++++++++++ if (player[myId].team == 1) { draw_tank_self(player[myId].tankAngle, blueTank, screen); draw_cannon_self(player[myId].cannonAngle, blueCannon, screen); } else
开发者ID:Urbansson,项目名称:Epic-Tank-Battle,代码行数:67,
示例17: mainintmain(int argc, char **argv){ bool shuffle_keys = true; if (argc != 3) { fprintf(stderr, "usage: %s [type] [input]/n", appname); fprintf(stderr, "type: specifies the dictionary type:/n"); fprintf(stderr, " h: height-balanced tree/n"); fprintf(stderr, " p: path-reduction tree/n"); fprintf(stderr, " r: red-black tree/n"); fprintf(stderr, " t: treap/n"); fprintf(stderr, " s: splay tree/n"); fprintf(stderr, " w: weight-balanced tree/n"); fprintf(stderr, " S: skiplist/n"); fprintf(stderr, " H: hashtable/n"); fprintf(stderr, " 2: hashtable 2/n"); fprintf(stderr, "input: text file consisting of newline-separated keys/n"); exit(EXIT_FAILURE); } srand(0xdeadbeef); dict_malloc_func = xmalloc; const char type = argv[1][0]; const char *container_name = NULL; dict *dct = create_dictionary(type, &container_name); if (!dct) quit("can't create container"); ASSERT(dict_verify(dct)); ASSERT(comp_count == 0); ASSERT(hash_count == 0); const size_t malloced_save = malloced; FILE *fp = fopen(argv[2], "r"); if (fp == NULL) quit("cant open file '%s': %s", argv[2], strerror(errno)); size_t nwords = 0; char buf[512]; while (fgets(buf, sizeof(buf), fp)) ++nwords; if (!nwords) quit("nothing read from file"); char **words = xmalloc(sizeof(*words) * nwords); rewind(fp); size_t words_read = 0; while (words_read < nwords && fgets(buf, sizeof(buf), fp)) { strtok(buf, "/n"); words[words_read++] = xstrdup(buf); } fclose(fp); if (words_read < nwords) quit("Only read %zu/%zu words!", words_read, nwords); printf("Loaded %zu keys from %s./n", nwords, argv[2]); malloced = malloced_save; size_t total_comp = 0, total_hash = 0, total_rotations = 0; struct rusage start, end; struct timeval total = { 0, 0 }; timer_start(&start); for (unsigned i = 0; i < nwords; i++) { dict_insert_result result = dict_insert(dct, words[i]); if (!result.inserted) quit("insert #%d failed for '%s'", i, words[i]); ASSERT(result.datum_ptr != NULL); ASSERT(*result.datum_ptr == NULL); *result.datum_ptr = words[i]; } timer_end(&start, &end, &total); printf(" %s container: %.02fkB/n", container_name, malloced_save * 1e-3); printf(" %s memory: %.02fkB/n", container_name, malloced * 1e-3); printf(" %s insert: %6.03fs %9zu cmp (%.02f/insert)", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6, comp_count, comp_count / (double) nwords); if (hash_count) printf(" %9zu hash", hash_count); printf("/n"); total_comp += comp_count; comp_count = 0; total_hash += hash_count; hash_count = 0; if (dict_is_sorted(dct) && type != 'S') { tree_base *tree = dict_private(dct); printf(" min path length: %zu/n", tree_min_path_length(tree)); printf(" max path length: %zu/n", tree_max_path_length(tree)); printf(" tot path length: %zu/n", tree_total_path_length(tree)); printf("insert rotations: %zu/n", tree->rotation_count); total_rotations += tree->rotation_count; tree->rotation_count = 0; } else if (type == 'S') { size_t counts[16] = { 0 }; size_t num_counts = skiplist_link_count_histogram(dict_private(dct), counts, sizeof(counts) / sizeof(counts[0])); size_t count_sum = 0;//.........这里部分代码省略.........
开发者ID:fmela,项目名称:libdict,代码行数:101,
示例18: mainint main() { double Mops, t1, t2, t3, t4, x1, x2; double sx, sy, tm, an, tt, gc; double sx_verify_value, sy_verify_value, sx_err, sy_err; int np; int i, ik, kk, l, k, nit; int k_offset, j; logical verified, timers_enabled; double dum[3] = {1.0, 1.0, 1.0}; char size[16]; FILE *fp; if ((fp = fopen("timer.flag", "r")) == NULL) { timers_enabled = false; } else { timers_enabled = true; fclose(fp); } //-------------------------------------------------------------------- // Because the size of the problem is too large to store in a 32-bit // integer for some classes, we put it into a string (for printing). // Have to strip off the decimal point put in there by the floating // point print statement (internal file) //-------------------------------------------------------------------- sprintf(size, "%15.0lf", pow(2.0, M+1)); j = 14; if (size[j] == '.') j--; size[j+1] = '/0'; printf("/n/n NAS Parallel Benchmarks (NPB3.3-SER-C) - EP Benchmark/n"); printf("/n Number of random numbers generated: %15s/n", size); verified = false; //-------------------------------------------------------------------- // Compute the number of "batches" of random number pairs generated // per processor. Adjust if the number of processors does not evenly // divide the total number //-------------------------------------------------------------------- np = NN; //-------------------------------------------------------------------- // Call the random number generator functions and initialize // the x-array to reduce the effects of paging on the timings. // Also, call all mathematical functions that are used. Make // sure these initializations cannot be eliminated as dead code. //-------------------------------------------------------------------- vranlc(0, &dum[0], dum[1], &dum[2]); dum[0] = randlc(&dum[1], dum[2]); for (i = 0; i < 2 * NK; i++) { x[i] = -1.0e99; } Mops = log(sqrt(fabs(MAX(1.0, 1.0)))); timer_clear(0); timer_clear(1); timer_clear(2); timer_start(0); t1 = A; vranlc(0, &t1, A, x); //-------------------------------------------------------------------- // Compute AN = A ^ (2 * NK) (mod 2^46). //-------------------------------------------------------------------- t1 = A; for (i = 0; i < MK + 1; i++) { t2 = randlc(&t1, t1); } an = t1; tt = S; gc = 0.0; sx = 0.0; sy = 0.0; for (i = 0; i < NQ; i++) { q[i] = 0.0; } //-------------------------------------------------------------------- // Each instance of this loop may be performed independently. We compute // the k offsets separately to take into account the fact that some nodes // have more numbers to generate than others //-------------------------------------------------------------------- k_offset = -1; for (k = 1; k <= np; k++) { kk = k_offset + k; t1 = S; t2 = an;//.........这里部分代码省略.........
开发者ID:nicolas-mosch,项目名称:DiscoPoP_Visualizer,代码行数:101,
示例19: mainint main(int argc, char * argv[]){ if (argc > 1){ parse_args(argc, argv); } const int size = n * n; float *mat = malloc(size * sizeof(float)); float *vec = malloc(n * sizeof(float)); float *output = malloc(n * sizeof(float)); float *expected = malloc(n * sizeof(float)); float *mat_transposed = malloc(n * n * sizeof(float)); generate_matrix(n, mat, range); generate_vector(n, vec, range); timing_t timer1; timer_start(&timer1); transpose(n, mat, mat_transposed); MatVecMultiply(size, n, mat_transposed, vec, output); timer_stop(&timer1); float sum = sum_vec(n, output); printf("%d %f %ld %ld/n", n, sum, timer1.realtime, timer1.cputime); if (trace == 1) { printf("/nInput matrix/n"); for (int i=0; i<n; i++){ for (int j=0; j<n; j++){ printf("%f " , mat[i*n+j]); } printf("/n"); } printf("/nInput vector /n"); for (int i=0; i<n; i++){ printf("%f " , vec[i]); } printf("/n/nResult/n"); for (int i=0; i<n; i++){ printf("%f " , output[i]); } printf("/n"); } else if (trace == 2) { multiply_CPU(n, mat, vec, expected); int status = check(n, output, expected); if (status) printf("Test failed./n"); else printf("Test passed OK!/n"); return status; } free(mat); free(vec); free(output); free(expected); free(mat_transposed); return 0;}
开发者ID:mznide,项目名称:dataflow-mat-vec,代码行数:71,
示例20: interval//.........这里部分代码省略......... return *info; } /* Get machine constants. */ safmin = lapackf77_dlamch("Safe minimum"); eps = lapackf77_dlamch("Precision"); smlnum = safmin / eps; bignum = 1. / smlnum; rmin = magma_dsqrt(smlnum); rmax = magma_dsqrt(bignum); /* Scale matrix to allowable range, if necessary. */ anrm = magmablas_dlansy(MagmaMaxNorm, uplo, n, dA, ldda, dwork); iscale = 0; sigma = 1; if (anrm > 0. && anrm < rmin) { iscale = 1; sigma = rmin / anrm; } else if (anrm > rmax) { iscale = 1; sigma = rmax / anrm; } if (iscale == 1) { magmablas_dlascl(uplo, 0, 0, 1., sigma, n, n, dA, ldda, info); } /* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */ // dsytrd work: e (n) + tau (n) + llwork (n*nb) ==> 2n + n*nb // dstedx work: e (n) + tau (n) + z (n*n) + llwrk2 (1 + 4*n + n^2) ==> 1 + 6n + 2n^2 inde = 0; indtau = inde + n; indwrk = indtau + n; indwk2 = indwrk + n*n; llwork = lwork - indwrk; llwrk2 = lwork - indwk2; magma_timer_t time=0; timer_start( time );#ifdef FAST_SYMV magma_dsytrd2_gpu(uplo, n, dA, ldda, w, &work[inde], &work[indtau], wA, ldwa, &work[indwrk], llwork, dwork, n*lddc, &iinfo);#else magma_dsytrd_gpu(uplo, n, dA, ldda, w, &work[inde], &work[indtau], wA, ldwa, &work[indwrk], llwork, &iinfo);#endif timer_stop( time ); timer_printf( "time dsytrd = %6.2f/n", time ); /* For eigenvalues only, call DSTERF. For eigenvectors, first call DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the tridiagonal matrix, then call DORMTR to multiply it to the Householder transformations represented as Householder vectors in A. */ if (! wantz) { lapackf77_dsterf(&n, w, &work[inde], info); magma_dmove_eig(range, n, w, &il, &iu, vl, vu, m); } else { timer_start( time ); magma_dstedx(range, n, vl, vu, il, iu, w, &work[inde], &work[indwrk], n, &work[indwk2], llwrk2, iwork, liwork, dwork, info); timer_stop( time ); timer_printf( "time dstedx = %6.2f/n", time ); timer_start( time ); magma_dmove_eig(range, n, w, &il, &iu, vl, vu, m); magma_dsetmatrix( n, *m, &work[indwrk + n* (il-1) ], n, dwork, lddc ); magma_dormtr_gpu(MagmaLeft, uplo, MagmaNoTrans, n, *m, dA, ldda, &work[indtau], dwork, lddc, wA, ldwa, &iinfo); magma_dcopymatrix( n, *m, dwork, lddc, dA, ldda ); timer_stop( time ); timer_printf( "time dormtr + copy = %6.2f/n", time ); } /* If matrix was scaled, then rescale eigenvalues appropriately. */ if (iscale == 1) { d__1 = 1. / sigma; blasf77_dscal(&n, &d__1, w, &ione); } work[0] = lwmin * one_eps; // round up iwork[0] = liwmin; magma_queue_destroy( stream ); magma_free( dwork ); return *info;} /* magma_dsyevd_gpu */
开发者ID:cjy7117,项目名称:DVFS-MAGMA,代码行数:101,
示例21: run_martet// run_martet: The game loop. Returns final score.int run_martet(SDL_Surface* screen, SDL_Surface* board) { Tetromino* active_tetromino; Tetromino* next_tetromino; // Create ingame menu struct Menu* ingame_menu = menu_create(); menu_addelement(ingame_menu, "Continue"); menu_addelement(ingame_menu, "Quit Current Game"); ingame_menu->active_element = &ingame_menu->elements[0]; ingame_menu->active_element->active = 1; int score = 0; srand((unsigned) time(NULL)); board_create(); next_tetromino = tetcreaterand(); update_status_bar(next_tetromino, screen, score); active_tetromino = tetcreaterand(); active_tetromino->position[0] = 4; struct Timer* timer = create_timer(); timer_change_alarm_interval(timer, GAME_SPEED); timer_start(timer); bool running = true; while (running){ int event = process_key_events(active_tetromino, tetaction); if (event == KEYEVENT_EXIT) exit(0); else if (event == KEYEVENT_MENU) { if (ingame_menu_martet(screen, board, ingame_menu) == 1) running = false; } else if (event == KEYEVENT_PAUSE) pause_martet(screen, board); if (timer_update(timer)) { // If collision and tetromino not deleted if ( tetmove('d', active_tetromino) == 0 && active_tetromino->color != TETROMINO_DELETE) { place_tetromino(active_tetromino); active_tetromino->color = TETROMINO_DELETE; } else if ( active_tetromino->color == TETROMINO_DELETE ) { free(active_tetromino); active_tetromino = next_tetromino; next_tetromino = tetcreaterand(); if (check_rows(&score)) { // If score has increased. timer_change_alarm_interval(timer, GAME_SPEED / sqrt( (double) score/5) + 1); } } if ( next_tetromino == NULL ) // If game over break; update_status_bar(next_tetromino, screen, score); } clear_surface(board, NULL); draw_board(board); draw_tetromino(board, active_tetromino); draw_ghost_tetromino(board, active_tetromino); draw_surface(0, 0, board, screen, NULL); SDL_Flip(screen); } if (active_tetromino) { free(active_tetromino); } free(next_tetromino); free(timer); menu_destroy(ingame_menu); return score;}
开发者ID:myrjola,项目名称:margames,代码行数:67,
示例22: test_timerstatic int test_timer(unsigned num){ int set = 0; /* reset state */ sw_count = 0; fired = 0; for (unsigned i = 0; i < MAX_CHANNELS; i++) { timeouts[i] = 0; args[i] = UINT_MAX; } /* initialize and halt timer */ if (timer_init(TIMER_DEV(num), TIM_SPEED, cb, (void *)(COOKIE * num)) < 0) { printf("TIMER_%u: ERROR on initialization - skipping/n/n", num); return 0; } else { printf("TIMER_%u: initialization successful/n", num); } timer_stop(TIMER_DEV(num)); printf("TIMER_%u: stopped/n", num); /* set each available channel */ for (unsigned i = 0; i < MAX_CHANNELS; i++) { unsigned timeout = ((i + 1) * CHAN_OFFSET); if (timer_set(TIMER_DEV(num), i, timeout) < 0) { break; } else { ++set; printf("TIMER_%u: set channel %u to %u/n", num, i, timeout); } } if (set == 0) { printf("TIMER_%u: ERROR setting any channel/n/n", num); return 0; } /* start the timer */ printf("TIMER_%u: starting/n", num); timer_start(TIMER_DEV(num)); /* wait for all channels to fire */ do { ++sw_count; } while (fired != set); /* collect results */ for (int i = 0; i < fired; i++) { if (args[i] != ((COOKIE * num) + i)) { printf("TIMER_%u: ERROR callback argument mismatch/n/n", num); return 0; } printf("TIMER_%u: channel %i fired at SW count %8u", num, i, (unsigned)timeouts[i]); if (i == 0) { printf(" - init: %8u/n", (unsigned)timeouts[i]); } else { printf(" - diff: %8u/n", (unsigned)(timeouts[i] - timeouts[i - 1])); } } return 1;}
开发者ID:LudwigKnuepfer,项目名称:RIOT,代码行数:61,
示例23: mainint main(int argc, char** argv ){ int i, iteration, itemp; int nthreads = 1; double timecounter, maxtime;/* Initialize the verification arrays if a valid class */ for( i=0; i<TEST_ARRAY_SIZE; i++ ) switch( CLASS ) { case 'S': test_index_array[i] = S_test_index_array[i]; test_rank_array[i] = S_test_rank_array[i]; break; case 'A': test_index_array[i] = A_test_index_array[i]; test_rank_array[i] = A_test_rank_array[i]; break; case 'W': test_index_array[i] = W_test_index_array[i]; test_rank_array[i] = W_test_rank_array[i]; break; case 'B': test_index_array[i] = B_test_index_array[i]; test_rank_array[i] = B_test_rank_array[i]; break; case 'C': test_index_array[i] = C_test_index_array[i]; test_rank_array[i] = C_test_rank_array[i]; break; };/* Printout initial NPB info */ printf( "/n/n NAS Parallel Benchmarks 2.3 OpenMP C version" " - IS Benchmark/n/n" ); printf( " Size: %d (class %c)/n", TOTAL_KEYS, CLASS ); printf( " Iterations: %d/n", MAX_ITERATIONS );/* Initialize timer */ timer_clear( 0 );/* Generate random number sequence and subsequent keys on all procs */ create_seq( 314159265.00, /* Random number gen seed */ 1220703125.00 ); /* Random number gen mult *//* Do one interation for free (i.e., untimed) to guarantee initialization of all data and code pages and respective tables */#pragma omp parallel rank( 1 );/* Start verification counter */ passed_verification = 0; if( CLASS != 'S' ) printf( "/n iteration/n" );/* Start timer */ timer_start( 0 );/* This is the main iteration */#pragma omp parallel private(iteration) for( iteration=1; iteration<=MAX_ITERATIONS; iteration++ ) {#pragma omp master if( CLASS != 'S' ) printf( " %d/n", iteration ); rank( iteration );#if defined(_OPENMP)#pragma omp master nthreads = omp_get_num_threads();#endif /* _OPENMP */ }/* End of timing, obtain maximum time of all processors */ timer_stop( 0 ); timecounter = timer_read( 0 );/* This tests that keys are in sequence: sorting of last ranked key seq occurs here, but is an untimed operation */ full_verify();/* The final printout */ if( passed_verification != 5*MAX_ITERATIONS + 1 ) passed_verification = 0; c_print_results( "IS", CLASS, TOTAL_KEYS, 0, 0,//.........这里部分代码省略.........
开发者ID:billhoffman,项目名称:rose-develop,代码行数:101,
示例24: mainint main(int argc, char **argv) { int i,j,k,iad; int aad,bad,cad; int N=16; if(argc>1) { N=atoi(argv[1]); } i=N/4; if(N>(i*4)) N=(i+1)*4; double l2=log(N)/log(2.0); int il2=(int)l2; if(il2<l2) il2++; int MSZ=pow(2,il2); int N4=N/4; printf("N=%d; N/4=%d; msize=%d/n",N,N4,MSZ);// actual memory allocation must be power of 2 although N can be any multiple of 4 float *a=(float *)_mm_malloc(MSZ*MSZ*sizeof(float),128); float *b=(float *)_mm_malloc(MSZ*MSZ*sizeof(float),128); float *c=(float *)_mm_malloc(MSZ*MSZ*sizeof(float),128); int iv=0;#pragma omp parallel for private (i,j,iv,iad) for(i=0; i<N; i++) { for(j=0; j<N; j++) { iv=j+i*N; iad=zorder2d(j,i); a[iad]=b[iad]=iv; c[iad]=0; } } tv ts; timer_reset(ts); timer_start(ts); for(i=0; i<N4; i++) {#pragma omp parallel for private (aad,bad,cad,i,j,k) for(j=0; j<N4; j++) { cad=16*zorder2d(j,i); for(k=0; k<N4; k++) { aad=16*zorder2d(k,i); bad=16*zorder2d(j,k); zmatmul(&a[aad],&b[bad],&c[cad]); } } } timer_stop(ts); printf("sec: %lf/n",timer_sec(ts)); float fN=N; printf("GFlops/s: %lf/n",(double)(fN*fN*(2*fN-1))/timer_sec(ts)/1000000000.0);// pmat(N,a);// pmat(N,b);// pmat(N,c); _mm_free(a); _mm_free(b); _mm_free(c);}
开发者ID:ryancoleman,项目名称:lotsofcoresbook1code,代码行数:67,
示例25: interval//.........这里部分代码省略......... smlnum = safmin / eps; bignum = 1. / smlnum; rmin = magma_ssqrt(smlnum); rmax = magma_ssqrt(bignum); /* Scale matrix to allowable range, if necessary. */ anrm = lapackf77_clanhe("M", uplo_, &n, A, &lda, rwork); iscale = 0; if (anrm > 0. && anrm < rmin) { iscale = 1; sigma = rmin / anrm; } else if (anrm > rmax) { iscale = 1; sigma = rmax / anrm; } if (iscale == 1) { lapackf77_clascl(uplo_, &izero, &izero, &d_one, &sigma, &n, &n, A, &lda, info); } /* Call CHETRD to reduce Hermitian matrix to tridiagonal form. */ // chetrd rwork: e (n) // cstedx rwork: e (n) + llrwk (1 + 4*N + 2*N**2) ==> 1 + 5n + 2n^2 inde = 0; indrwk = inde + n; llrwk = lrwork - indrwk; // chetrd work: tau (n) + llwork (n*nb) ==> n + n*nb // cstedx work: tau (n) + z (n^2) // cunmtr work: tau (n) + z (n^2) + llwrk2 (n or n*nb) ==> 2n + n^2, or n + n*nb + n^2 indtau = 0; indwrk = indtau + n; indwk2 = indwrk + n*n; llwork = lwork - indwrk; llwrk2 = lwork - indwk2; magma_timer_t time=0; timer_start( time ); magma_chetrd(uplo, n, A, lda, w, &rwork[inde], &work[indtau], &work[indwrk], llwork, &iinfo); timer_stop( time ); timer_printf( "time chetrd = %6.2f/n", time ); /* For eigenvalues only, call SSTERF. For eigenvectors, first call CSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the tridiagonal matrix, then call CUNMTR to multiply it to the Householder transformations represented as Householder vectors in A. */ if (! wantz) { lapackf77_ssterf(&n, w, &rwork[inde], info); magma_smove_eig(range, n, w, &il, &iu, vl, vu, m); } else { timer_start( time ); if (MAGMA_SUCCESS != magma_smalloc( &dwork, 3*n*(n/2 + 1) )) { *info = MAGMA_ERR_DEVICE_ALLOC; return *info; } magma_cstedx(range, n, vl, vu, il, iu, w, &rwork[inde], &work[indwrk], n, &rwork[indrwk], llrwk, iwork, liwork, dwork, info); magma_free( dwork ); timer_stop( time ); timer_printf( "time cstedx = %6.2f/n", time ); timer_start( time ); magma_smove_eig(range, n, w, &il, &iu, vl, vu, m); magma_cunmtr(MagmaLeft, uplo, MagmaNoTrans, n, *m, A, lda, &work[indtau], &work[indwrk + n * (il-1) ], n, &work[indwk2], llwrk2, &iinfo); lapackf77_clacpy("A", &n, m, &work[indwrk + n * (il-1)], &n, A, &lda); timer_stop( time ); timer_printf( "time cunmtr + copy = %6.2f/n", time ); } /* If matrix was scaled, then rescale eigenvalues appropriately. */ if (iscale == 1) { if (*info == 0) { imax = n; } else { imax = *info - 1; } d__1 = 1. / sigma; blasf77_sscal(&imax, &d__1, w, &ione); } work[0] = magma_cmake_lwork( lwmin ); rwork[0] = magma_smake_lwork( lrwmin ); iwork[0] = liwmin; return *info;} /* magma_cheevdx */
开发者ID:xulunfan,项目名称:magma,代码行数:101,
示例26: mainint main() { const int n = 16 * 1024; const int m = 16 * 1024; float ** a; test_timer_t timer = timer_build(); { timer_start(timer); a = create_array(n, m); kernel_0(n, m, a, 3.5); free_array(a); timer_stop(timer); printf("#0 : %d/n", timer->delta); } { timer_start(timer); a = create_array(n, m); kernel_1(n, m, a, 3.5); free_array(a); timer_stop(timer); printf("#1 : %d/n", timer->delta); } { timer_start(timer); a = create_array(n, m); kernel_2(n, m, a, 3.5); free_array(a); timer_stop(timer); printf("#2 : %d/n", timer->delta); } { timer_start(timer); a = create_array(n, m); kernel_3(n, m, a, 3.5); free_array(a); timer_stop(timer); printf("#3 : %d/n", timer->delta); } return 0;}
开发者ID:8l,项目名称:rose,代码行数:63,
示例27: dimension//.........这里部分代码省略......... } /* Get machine constants. */ safmin = lapackf77_slamch("Safe minimum"); eps = lapackf77_slamch("Precision"); smlnum = safmin / eps; bignum = 1. / smlnum; rmin = magma_ssqrt( smlnum ); rmax = magma_ssqrt( bignum ); /* Scale matrix to allowable range, if necessary. */ anrm = lapackf77_clanhe( "M", uplo_, &n, A, &lda, rwork ); iscale = 0; if (anrm > 0. && anrm < rmin) { iscale = 1; sigma = rmin / anrm; } else if (anrm > rmax) { iscale = 1; sigma = rmax / anrm; } if (iscale == 1) { lapackf77_clascl( uplo_, &izero, &izero, &d_one, &sigma, &n, &n, A, &lda, info ); } /* Call CHETRD to reduce Hermitian matrix to tridiagonal form. */ // chetrd rwork: e (n) // cstedx rwork: e (n) + llrwk (1 + 4*N + 2*N**2) ==> 1 + 5n + 2n^2 inde = 0; indrwk = inde + n; llrwk = lrwork - indrwk; // chetrd work: tau (n) + llwork (n*nb) ==> n + n*nb // cstedx work: tau (n) + z (n^2) // cunmtr work: tau (n) + z (n^2) + llwrk2 (n or n*nb) ==> 2n + n^2, or n + n*nb + n^2 indtau = 0; indwrk = indtau + n; indwk2 = indwrk + n*n; llwork = lwork - indwrk; llwrk2 = lwork - indwk2; magma_timer_t time=0; timer_start( time ); magma_chetrd( uplo, n, A, lda, w, &rwork[inde], &work[indtau], &work[indwrk], llwork, &iinfo ); timer_stop( time ); timer_printf( "time chetrd = %6.2f/n", time ); /* For eigenvalues only, call SSTERF. For eigenvectors, first call * CSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the * tridiagonal matrix, then call CUNMTR to multiply it to the Householder * transformations represented as Householder vectors in A. */ if (! wantz) { lapackf77_ssterf( &n, w, &rwork[inde], info ); } else { timer_start( time ); if (MAGMA_SUCCESS != magma_smalloc( &dwork, 3*n*(n/2 + 1) )) { *info = MAGMA_ERR_DEVICE_ALLOC; return *info; } magma_cstedx( MagmaRangeAll, n, 0., 0., 0, 0, w, &rwork[inde], &work[indwrk], n, &rwork[indrwk], llrwk, iwork, liwork, dwork, info ); magma_free( dwork ); timer_stop( time ); timer_printf( "time cstedx = %6.2f/n", time ); timer_start( time ); magma_cunmtr( MagmaLeft, uplo, MagmaNoTrans, n, n, A, lda, &work[indtau], &work[indwrk], n, &work[indwk2], llwrk2, &iinfo ); lapackf77_clacpy( "A", &n, &n, &work[indwrk], &n, A, &lda ); timer_stop( time ); timer_printf( "time cunmtr + copy = %6.2f/n", time ); } /* If matrix was scaled, then rescale eigenvalues appropriately. */ if (iscale == 1) { if (*info == 0) { imax = n; } else { imax = *info - 1; } d__1 = 1. / sigma; blasf77_sscal( &imax, &d__1, w, &ione ); } work[0] = MAGMA_C_MAKE( lwmin * one_eps, 0 ); // round up rwork[0] = lrwmin * one_eps; iwork[0] = liwmin; return *info;} /* magma_cheevd */
开发者ID:cjy7117,项目名称:FT-MAGMA,代码行数:101,
示例28: mainint main(int argc, char **argv){ Timer *render_timer; Sdl *sdl; FILE *out; Colour *buffer; Pixel *pixels; int num_pixels; SDL_Event event = {0}; if (argc < 2) return 1; sdl = sdl_load(argv[1]); if (sdl == NULL) return 1; if (!init_SDL()) return 1; num_pixels = config->width * config->height; buffer = calloc(num_pixels, sizeof(Colour)); pixels = calloc(num_pixels, sizeof(Pixel)); for (int j = 0; j < config->height; j++) for (int i = 0; i < config->width; i++) { pixels[j*config->width + i].x = i; pixels[j*config->width + i].y = j; } srand(time(NULL)); shuffle_pixels(pixels, config->width, config->height); srand(0x20071208); /* START */ render_timer = timer_start("Rendering"); for (int i = 0; i < num_pixels; i++) { Camera *cam = scene->camera; Colour c; Ray r; int x = pixels[i].x, y = pixels[i].y; /* The last parameter is the near plane, which is irrelevant for * the moment. */ r = camera_ray(cam, x, y, 1); c = ray_colour(r, 0); buffer[config->width*y + x] = c; put_pixel(display_surface, x, y, c); if (i % config->width == 0) { SDL_Flip(display_surface); while (SDL_PollEvent(&event)) if (event.type == SDL_QUIT) return 0; } } /* STOP */ timer_stop(render_timer); timer_diff_print(render_timer); printf("%.2f kilopixels per second/n", num_pixels/1000./(timer_diff(render_timer))); out = fopen("ray.ppm", "w"); ppm_write(buffer, config->width, config->height, out); free(buffer); fclose(out); SDL_Flip(display_surface); while(1) { while (SDL_WaitEvent(&event)) if (event.type == SDL_QUIT) return 0; else if (event.type == SDL_VIDEOEXPOSE) SDL_Flip(display_surface); } return 0;}
开发者ID:kaspermeerts,项目名称:cg,代码行数:84,
注:本文中的timer_start函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ timer_stats_account_hrtimer函数代码示例 C++ timer_setup函数代码示例 |