PQB3EKQ6MBCXPTW4HB7SGMSTOTYMB3EFZX2573OFCQI6PSOEKCSQC }vector<cGH> thread_local_cctkGH;// Create a new cGH, copying those data that are set by the flesh, and// allocating space for these data that are set per thread by the drivervoid clone_cctkGH(cGH *restrict cctkGH, const cGH *restrict sourceGH) {// Copy all fields by default*cctkGH = *sourceGH;// Allocate most fields anewcctkGH->cctk_gsh = new int[dim];cctkGH->cctk_lsh = new int[dim];cctkGH->cctk_lbnd = new int[dim];cctkGH->cctk_ubnd = new int[dim];cctkGH->cctk_ash = new int[dim];cctkGH->cctk_to = new int[dim];cctkGH->cctk_from = new int[dim];cctkGH->cctk_delta_space = new CCTK_REAL[dim];cctkGH->cctk_origin_space = new CCTK_REAL[dim];cctkGH->cctk_bbox = new int[2 * dim];cctkGH->cctk_levfac = new int[dim];cctkGH->cctk_levoff = new int[dim];cctkGH->cctk_levoffdenom = new int[dim];cctkGH->cctk_nghostzones = new int[dim];const int numvars = CCTK_NumVars();cctkGH->data = new void **[numvars];for (int vi = 0; vi < numvars; ++vi)cctkGH->data[vi] = new void *[CCTK_DeclaredTimeLevelsVI(vi)];
}// Update fields that carry state and change over timevoid update_cctkGH(cGH *restrict cctkGH, const cGH *restrict sourceGH) {cctkGH->cctk_iteration = sourceGH->cctk_iteration;for (int d = 0; d < dim; ++d)cctkGH->cctk_origin_space[d] = sourceGH->cctk_origin_space[d];for (int d = 0; d < dim; ++d)cctkGH->cctk_delta_space[d] = sourceGH->cctk_delta_space[d];cctkGH->cctk_time = sourceGH->cctk_time;cctkGH->cctk_delta_time = sourceGH->cctk_delta_time;
setup_cctkGH(cctkGH);enter_global_mode(cctkGH);enter_level_mode(cctkGH);int max_threads = omp_get_max_threads();thread_local_cctkGH.resize(max_threads);for (int n = 0; n < max_threads; ++n) {cGH *restrict threadGH = &thread_local_cctkGH.at(n);clone_cctkGH(threadGH, cctkGH);setup_cctkGH(threadGH);enter_global_mode(threadGH);enter_level_mode(threadGH);}
for (MFIter mfi(mfab, mfitinfo); mfi.isValid(); ++mfi) {enter_local_mode(cctkGH, mfi);CCTK_CallFunction(function, attribute, data);
{cGH *restrict threadGH = &thread_local_cctkGH.at(omp_get_thread_num());update_cctkGH(threadGH, cctkGH);for (MFIter mfi(mfab, mfitinfo); mfi.isValid(); ++mfi) {enter_local_mode(threadGH, mfi);CCTK_CallFunction(function, attribute, threadGH);}
void setup_cctkGH(cGH *restrict cctkGH);void enter_global_mode(cGH *restrict cctkGH);void leave_global_mode(cGH *restrict cctkGH);void enter_level_mode(cGH *restrict cctkGH);void leave_level_mode(cGH *restrict cctkGH);void enter_local_mode(cGH *restrict cctkGH, const MFIter &mfi);void leave_local_mode(cGH *restrict cctkGH);