/* size(var) needs to be num_cell */ void compute_upto_level_hierarchy( void (*flevel)(int , int , int *, float *), float (*favg)(int , float *), int top_level, float *var) { MESH_RUN_DECLARE(level,cell); float *var_level; MESH_RUN_OVER_LEVELS_BEGIN(level,_MaxLevel,top_level); var_level = cart_alloc(float,_Num_level_cells); flevel(level,_Num_level_cells,_Level_cells,var_level); #pragma omp parallel for default(none), private(_Index,cell), shared(_Num_level_cells,_Level_cells,var_level,var,cell_child_oct,cell_vars,level, units,constants,favg) MESH_RUN_OVER_CELLS_OF_LEVEL_BEGIN(cell); if(cell_is_leaf(cell)) { var[cell] = MAX(0.0,var_level[_Index]); } else { var[cell] = favg(cell,var); } cart_assert( var[cell]>=0 && !(var[cell]!=var[cell]) ); MESH_RUN_OVER_CELLS_OF_LEVEL_END; cart_free(var_level); MESH_RUN_OVER_LEVELS_END; }
int main(int argc, char *argv[]) { if (argc < 4) { std::cerr << "usage: run <protocol> <n> <number of runs>" << std::endl; exit(-1); } protocol_fn protf; if (!strcmp(argv[1], "pcl")) protf = pcl; else if (!strcmp(argv[1], "kdk")) protf = kdk; else { std::cerr << "unknown protocol" << std::endl; exit(-1); } int n = atoi(argv[2]); if (n <= 0) { std::cerr << "n must be positive" << std::endl; exit(-1); } int nruns = atoi(argv[3]); if (nruns <= 0) { std::cerr << "number of runs must be positive" << std::endl; exit(-1); } float *times = new float[nruns]; protf((unsigned int)n, times, (size_t)nruns); std::cout << n << "\t" << favg(times, nruns) << "\t" << fmax(times, nruns) << "\t" << fmin(times, nruns) << "\t" << fstd(times, nruns) << std::endl; delete[] times; }