//measure how long it takes to spawn threads with a simple argumentless function void run_tests(uint64_t num, int threads){ double time1, time2; int i; vector<hpx::thread> funcs; //first measure how long it takes to spawn threads //then measure how long it takes to join them back together printf("\nNOTE: for now, this benchmark is intended to obtain the \n" " percentage of total runtime spent on context switching when\n" " running on a single OS thread\n\n"); high_resolution_timer t; for(i = 0; i < threads; i++) loop_function(num); time1 = t.elapsed(); t.restart(); for(i = 0; i < threads; ++i) funcs.push_back(hpx::thread(&loop_function, num)); for(i = 0; i < threads; ++i) funcs[i].join(); time2 = t.elapsed(); printf("Executing the function %d times sequentially yields a total time of " "%f s\n", threads, time1); printf("Executing the function %d times simultaneously yields a total time of " "%f s\n\n", threads, time2); printf("Estimated time spent context switching is %f s\n\n", time2-time1); printf("Estimated percentage of time spent context switching is %% %f\n\n", (1-time1/(time2))*100); }
int loop_function(int n, int step) { if (n <= 1) return 0; /* Not Prime */ if (step > n/2) return 1; /* Prime */ if (n % step == 0) return 0; /* Not Prime */ return loop_function(n, step+1); /* Same as stepping through a for-loop but using a function */ }
static int run_benchmark(int async_jobs, int (*loop_function)(void *), loopargs_t *loopargs) { int job_op_count = 0; int total_op_count = 0; int num_inprogress = 0; int error = 0, i = 0, ret = 0; OSSL_ASYNC_FD job_fd = 0; size_t num_job_fds = 0; run = 1; if (async_jobs == 0) { return loop_function((void *)&loopargs); } return 1234567; }
int do_integrate(float t_start, float t_stop, int n_points) { realtype reltol, t; N_Vector y, abstol; void *cvode_mem; int flag, flagr, iout; y = abstol = NULL; cvode_mem = NULL; /* Create serial vector of length NEQ for I.C. and abstol */ y = N_VNew_Serial(NEQ); if (check_flag((void *)y, "N_VNew_Serial", 0)) return(1); abstol = N_VNew_Serial(NEQ); if (check_flag((void *)abstol, "N_VNew_Serial", 0)) return(1); //Setup the initial state values: setup_initial_states(y); setup_tolerances(abstol); /* Set the scalar relative tolerance */ reltol = RTOL; /* Call CVodeCreate to create the solver memory and specify the * Backward Differentiation Formula and the use of a Newton iteration */ cvode_mem = CVodeCreate(CV_BDF, CV_NEWTON); if (check_flag((void *)cvode_mem, "CVodeCreate", 0)) return(1); /* Call CVodeInit to initialize the integrator memory and specify the * user's right hand side function in y'=f(t,y), the inital time T0, and * the initial dependent variable vector y. */ flag = CVodeInit(cvode_mem, f, t_start, y); if (check_flag(&flag, "CVodeInit", 1)) return(1); /* Call CVodeSVtolerances to specify the scalar relative tolerance * and vector absolute tolerances */ flag = CVodeSVtolerances(cvode_mem, reltol, abstol); if (check_flag(&flag, "CVodeSVtolerances", 1)) return(1); /* Call CVDense to specify the CVDENSE dense linear solver */ flag = CVDense(cvode_mem, NEQ); if (check_flag(&flag, "CVDense", 1)) return(1); /* Set the Jacobian routine to Jac (user-supplied) */ flag = CVDlsSetDenseJacFn(cvode_mem, Jac); if (check_flag(&flag, "CVDlsSetDenseJacFn", 1)) return(1); /* In loop, call CVode, print results, and test for error.*/ printf(" \n3-species kinetics problem\n\n"); iout = 0; int i=0; for(i=1;i< n_points; i++) { float t_next = t_start + (t_stop-t_start)/n_points * i; printf("Advancing to: %f", t_next); flag = CVode(cvode_mem, t_next, y, &t, CV_NORMAL); loop_function(t,y); PrintOutput(t, Ith(y,1), Ith(y,2), Ith(y,3)); //printf("MH: %d %f",iout,t_next); if (check_flag(&flag, "CVode", 1)) break; assert(flag==CV_SUCCESS); } /* Print some final statistics */ PrintFinalStats(cvode_mem); /* Free y and abstol vectors */ N_VDestroy_Serial(y); N_VDestroy_Serial(abstol); /* Free integrator memory */ CVodeFree(&cvode_mem); return(0); }
int is_prime_number(int n) { return loop_function(n, 2); }
int main() { int_ptr = loop_function(loop_ptr); return 0; }