void tick_callback::irqhandler(void) { systick::irqhandler(); if(callback && (get_elapsed_ms() > callback_delay)) { callback(); reset(); } }
aldl_record_t *aldl_create_record(aldl_conf_t *aldl) { /* get memory pool addresses */ aldl_record_t *rec = &recordbuffer[indexbuffer]; rec->data = &databuffer[indexbuffer * aldl->n_defs]; /* advance pool index (for next time around) */ if(indexbuffer > aldl->bufsize - 2) { /* end of buffer */ indexbuffer = 0; /* return to beginning */ } else { indexbuffer++; } /* timestamp record */ rec->t = get_elapsed_ms(firstrecordtime); #ifdef TIMESTAMP_WRAPAROUND /* handle wraparound if we're 100 seconds before time limit */ if(rec->t > ULONG_MAX - 100000) firstrecordtime = get_time(); #endif return rec; }
void dlaed0_m(long NGRP, long NCORE, long N, double *D, double *E, double *Q, long LDQ, double *WORK, long *IWORK) /* computes all eigenvalues and corresponding eigenvectors of a symmetric tridiagonal matrix using the divide-and-conquer eigenvalue algorithm. We will have diag(D(in)) + diag(E, 1) + diag(E, -1) = Q * diag(D(out)) + Q'. */ { long subpbs; // number of subproblems long i, j, k, submat, smm1, msd2, matsiz; long *partition = &IWORK[0]; long *perm1 = &IWORK[4*N]; long pbmax; long NCOREP; // # cores allocated to each compute group double tmp; // Determine the size and placement of the submatrices, and save in // the leading elements of IWORK. partition[0] = N; subpbs = 1; while (partition[subpbs-1] > SMLSIZ) { for (j = subpbs-1; j >= 0; j--) { partition[2*j + 1] = (partition[j] + 1) / 2; partition[2*j] = partition[j] / 2; } subpbs *= 2; } for (j = 1; j < subpbs; j++) partition[j] += partition[j-1]; // Divide the matrix into subpbs submatricies of size at most // SMLSIZ+1 using rank-1 modifications (cuts). for (i = 0; i < subpbs - 1; i++) { submat = partition[i]; smm1 = submat - 1; D[smm1] -= fabs(E[smm1]); D[submat] -= fabs(E[smm1]); } // Solve each submatrix eigenvalue problem at the bottom of the divide and // conquer tree. omp_set_num_threads(omp_get_num_procs()); #pragma omp parallel for default(none) \ private(i, j, k, submat, matsiz) firstprivate(subpbs, LDQ) \ shared(partition, D, E, Q, WORK, perm1) for (i = -1; i < subpbs - 1; i++) { if (i == -1) { submat = 0; matsiz = partition[0]; } else { submat = partition[i]; matsiz = partition[i+1] - partition[i]; } LAPACKE_dsteqr_work(LAPACK_COL_MAJOR, 'I', matsiz, &D[submat], &E[submat], &Q[submat + submat * LDQ], LDQ, &WORK[2*submat]); k = 0; for (j = submat; j < partition[i+1]; j++) perm1[j] = k++; } // Successively merge eigensystems of adjacent submatrices into // eigensystem for the corresponding larger matrix. pbmax = 0; struct timeval timer1, timer2; omp_set_num_threads(NGRP); while (subpbs > 1) { // update pbmax. for (j = 0; j < subpbs/2; j++) { i = 2*j - 1; matsiz = (i == -1) ? partition[1] : partition[i+2]-partition[i]; if (matsiz > pbmax) pbmax = matsiz; } get_time(&timer1); #pragma omp parallel for default(none) \ private(i, j, submat, matsiz, msd2, NCOREP) \ firstprivate(N, subpbs, LDQ, NGRP, NCORE) \ shared(partition, D, Q, perm1, E, WORK, IWORK) for (j = 0; j < subpbs/2; j++) { i = 2*j - 1; if (i == -1) { submat = 0; matsiz = partition[1]; msd2 = partition[0]; } else { submat = partition[i]; matsiz = partition[i+2] - partition[i]; msd2 = matsiz / 2; } // Merge lower order eigensystems (of size msd2 and matsiz - msd2) // into an eigensystem of size matsiz. NCOREP = NCORE / ((subpbs/2 >= NGRP) ? NGRP : (subpbs/2)); dlaed1_cpu(NCOREP, matsiz, &D[submat], &Q[submat + submat * LDQ], LDQ, &perm1[submat], E[submat+msd2-1], msd2, &WORK[submat*(2*N+2*N*N)/N], &IWORK[subpbs+3*submat]); } get_time(&timer2); tmp = get_elapsed_ms(timer1, timer2) / 1000.0 / subpbs; printf("%ld:%ld:%.20lf\n", pbmax, NCORE, tmp); fprintf(stderr, " subproblem size = %ld, cost per subproblem = %.3lf s\n", pbmax, tmp); // update partition. for (i = -1; i < subpbs - 2; i += 2) partition[(i-1)/2 + 1] = partition[i+2]; subpbs /= 2; } // Re-merge the eigenvalues and eigenvectors which were deflated at the // final merge step. // D = D(perm1); for (i = 0; i < N; i++) WORK[i] = D[perm1[i]]; cblas_dcopy(N, WORK, 1, D, 1); // Q = Q(perm1); for (j = 0; j < N; j++) { i = perm1[j]; cblas_dcopy(N, &Q[i * LDQ], 1, &WORK[(j + 1) * N], 1); } LAPACKE_dlacpy(LAPACK_COL_MAJOR, 'A', N, N, &WORK[N], N, Q, LDQ); }
/* function for individual threads */ void *Individual( void *info ) { long min_queue_time = 999999999; //minimum time spent in queue long avg_queue_time = 0; //average time spent in queue long max_queue_time = 0; //maximum time spent in queue long tot_queue_time = 0; //total time spent in queue long tot_waits = 0; //total number of times waited in queue struct timeval before; //to keep track of time elapsed struct timeval after; thread_info_t * usr = (thread_info_t *) info; /* generate a random loop count based on average */ int rand_loop_count = (int) floor( get_distributed_rand ( loop_count ) ); // printf("Inside thread %d: Looping %d times\n", user->thread_number, rand_loop_count); int i; //for loop for (i = 0; i < rand_loop_count; i++) { int rand_arrival_time = (int) floor(get_distributed_rand( arrival_time )); int rand_stay_time = (int) floor(get_distributed_rand( stay_time )); /* wait for a random length of time based on arrival_time */ usleep( rand_arrival_time * MICRO_SEC ); gettimeofday(&before, NULL); //get time before int waited = Enter( &rr, usr->thread_gender ); gettimeofday(&after, NULL); //get time after /* wait for a random length of time based on stay time */ usleep( rand_stay_time * MICRO_SEC ); Leave( &rr ); //do some time calculations long elapsed = get_elapsed_ms(&before, &after); if (waited) { if (elapsed > max_queue_time) { max_queue_time = elapsed; } if (elapsed < min_queue_time) { min_queue_time = elapsed; } tot_waits++; tot_queue_time += elapsed; } } // get average from the total / the loop count if (tot_waits) { avg_queue_time = tot_queue_time / tot_waits; } //change value for printing if (min_queue_time == 999999999) { min_queue_time = 0; } /* print final information regarding thread */ pthread_mutex_lock ( &print_mutex ); //lock so only this thread prints printf("\nThread %d has Finalizeed.\n", usr->thread_number); if (usr->thread_gender == 0) { printf("Gender: Male\n"); } else { printf("Gender: Female\n"); } printf("# Loops: %d\n", rand_loop_count); printf("Waited in queue: %ld times\n", tot_waits); printf("Total queue time: %ld ms\n", tot_queue_time); printf("Min queue time: %ld ms\n", min_queue_time); printf("Max queue time: %ld ms\n", max_queue_time); printf("Avg queue time: %ld ms\n", avg_queue_time); pthread_mutex_unlock( &print_mutex ); //unlock! pthread_exit(NULL); }