void ops_dat_fetch_data(ops_dat dat, int part, char *data) { ops_get_data(dat); int lsize[OPS_MAX_DIM] = {1}; int ldisp[OPS_MAX_DIM] = {1}; ops_dat_get_extents(dat, part, ldisp, lsize); lsize[0] *= dat->elem_size/dat->dim; //now in bytes if (dat->block->dims>3) {ops_printf("Error, ops_dat_fetch_data not implemented for dims>3\n"); exit(-1);} if (OPS_soa && dat->dim > 1) {ops_printf("Error, ops_dat_fetch_data not implemented for SoA\n"); exit(-1);} for (int k = 0; k < lsize[2]; k++) for (int j = 0; j < lsize[1]; j++) memcpy(&data[k*lsize[0]*lsize[1]+j*lsize[0]], &dat->data[((j-dat->d_m[1] + (k-dat->d_m[2])*dat->size[1])*dat->size[0] - dat->d_m[0])* dat->elem_size], lsize[0]); }
void tea_leaf_cheby_first_step(double *ch_alphas, double *ch_betas, int *fields, double *error, double *theta, double cn, int max_cheby_iters, int *est_itc, double solve_time, double rx, double ry) { double bb = 0; // calculate 2 norm of u0 tea_leaf_calc_2norm(0, &bb); // initialise 'p' array tea_leaf_cheby_init(u,u0,vector_p,vector_r,vector_Mi,vector_w,vector_z,vector_Kx,vector_Ky,tri_cp,tri_bfp,rx,ry,*theta,tl_preconditioner_type); // if (profiler_on) halo_time = timer() update_halo(fields,1); // if (profiler_on) solve_time = solve_time + (timer()-halo_time) tea_leaf_cheby_iterate(u,u0,vector_p,vector_r,vector_Mi,vector_w,vector_z,vector_Kx,vector_Ky,tri_cp,tri_bfp,ch_alphas, ch_betas, rx,ry,1,tl_preconditioner_type); tea_leaf_calc_2norm(1, error); double it_alpha = eps/2.0*sqrt(bb/(*error));//eps*bb/(4.0*(*error)); double gamm = (sqrt(cn) - 1.0)/(sqrt(cn) + 1.0); *est_itc = round(log(it_alpha)/(log(gamm))); ops_fprintf(g_out," est itc\n%11d\n",*est_itc); ops_printf(" est itc\n%11d\n",*est_itc); }
int main(int argc, const char **argv) { ops_init(argc, argv, 5); ops_init_backend(); ops_printf("Hello world from OPS!\n\n"); ops_block block = ops_decl_block_hdf5(3, "grid0", "write_data.h5"); ops_dat single = ops_decl_dat_hdf5(block, 1, "double", "single", "write_data.h5"); ops_dat multi = ops_decl_dat_hdf5(block, 2, "double", "multi", "write_data.h5"); ops_dat integ = ops_decl_dat_hdf5(block, 1, "int", "integ", "write_data.h5"); ops_partition("empty_string_that_does_nothing_yet"); ops_diagnostic_output(); ops_fetch_block_hdf5_file(block, "read_data.h5"); ops_fetch_dat_hdf5_file(multi, "read_data.h5"); ops_fetch_dat_hdf5_file(single, "read_data.h5"); ops_fetch_dat_hdf5_file(integ, "read_data.h5"); int my_const; ops_get_const_hdf5("my_const", 1, "int", (char *)&my_const, "write_data.h5"); printf("Read const: %d\n", my_const); char buffer[50]; ops_get_const_hdf5("my_text", 11, "char", buffer, "write_data.h5"); printf("Read text: %s\n", buffer); ops_write_const_hdf5("my_const", 1, "int", (char *)&my_const, "read_data.h5"); ops_write_const_hdf5("my_text", 11, "char", (char *)buffer, "read_data.h5"); ops_timing_output(stdout); ops_printf("\nSucessful exit from OPS!\n"); ops_exit(); }
void timestep() { double dtlp; double kernel_time, c, t; if(profiler_on) ops_timers_core(&c,&kernel_time); //calc_dt(&dt) dt = dtinit; // if(profiler_on) profiler%timestep=profiler%timestep+(timer()-kernel_time) ops_fprintf(g_out, " Step %8d time %.7lf timestep %-10.2E\n", step, currtime, dt); ops_printf(" Step %8d time %.7lf timestep %-10.2E\n", step, currtime, dt); }
void field_summary() { double qa_diff; //initialize sizes using global values int x_min = field.x_min; int x_max = field.x_max; int y_min = field.y_min; int y_max = field.y_max; int rangexy_inner[] = {x_min,x_max,y_min,y_max}; // inner range without border double vol= 0.0 , mass = 0.0, ie = 0.0, temp = 0.0; ops_par_loop(field_summary_kernel, "field_summary_kernel", tea_grid, 2, rangexy_inner, ops_arg_dat(volume, 1, S2D_00, "double", OPS_READ), ops_arg_dat(density, 1, S2D_00, "double", OPS_READ), ops_arg_dat(energy1, 1, S2D_00, "double", OPS_READ), ops_arg_dat(u, 1, S2D_00, "double", OPS_READ), ops_arg_reduce(red_vol, 1, "double", OPS_INC), ops_arg_reduce(red_mass, 1, "double", OPS_INC), ops_arg_reduce(red_ie, 1, "double", OPS_INC), ops_arg_reduce(red_temp, 1, "double", OPS_INC)); //printf("mass = %lf\n",mass); ops_reduction_result(red_vol,&vol); ops_reduction_result(red_mass,&mass); ops_reduction_result(red_ie,&ie); ops_reduction_result(red_temp,&temp); ops_fprintf(g_out,"\n"); ops_fprintf(g_out,"\n Time %lf\n",clover_time); ops_fprintf(g_out," %-10s %-10s %-15s %-10s %-s\n", " Volume"," Mass"," Density"," Internal Energy","Temperature"); ops_fprintf(g_out," step: %3d %-10.3E %-10.3E %-15.3E %-10.3E %-.3E", step, vol, mass, mass/vol, ie, temp); if(complete == 1) { if(test_problem>0) { if (test_problem == 1) qa_diff = fabs((100.0 * (temp / 157.55084183279294)) - 100.0); if (test_problem == 2) // tea_bm_short.in qa_diff = fabs((100.0 * (temp / 106.27221178646569)) - 100.0); if (test_problem == 3) qa_diff = fabs((100.0 * (temp / 99.955877498324000)) - 100.0); if (test_problem == 4) qa_diff = fabs((100.0 * (temp / 97.277332050749976)) - 100.0); if (test_problem == 5) qa_diff = fabs((100.0 * (temp / 95.462351583362249)) - 100.0); ops_printf("Test problem %3d is within %-10.7E%% of the expected solution\n",test_problem, qa_diff); ops_fprintf(g_out,"\nTest problem %3d is within %10.7E%% of the expected solution\n",test_problem, qa_diff); if(qa_diff < 0.001) { ops_printf(" This test is considered PASSED\n"); ops_fprintf(g_out," This test is considered PASSED\n"); } else { ops_printf(" This test is considered FAILED\n"); ops_fprintf(g_out," This test is considered FAILED\n"); } } } fflush(g_out); //ops_exit();//exit for now //exit(0); }
int main(int argc, const char **argv) { c0 = 0.500000000000000; rc0 = 1.0 / 280.0; rc1 = 4.0 / 105.0; rc2 = 1.0 / 5.0; rc3 = 4.0 / 5.0; nx0 = 1000; deltai0 = 0.00100000000000000; deltat = 0.000400000000000000; rkold[0] = 1.0 / 4.0; rkold[1] = 3.0 / 20.0; rkold[2] = 3.0 / 5.0; rknew[0] = 2.0 / 3.0; rknew[1] = 5.0 / 12.0; rknew[2] = 3.0 / 5.0; ops_init(argc, argv, 1); ops_init_backend(); ops_decl_const2("c0", 1, "double", &c0); ops_decl_const2("rc0", 1, "double", &rc0); ops_decl_const2("rc1", 1, "double", &rc1); ops_decl_const2("rc2", 1, "double", &rc2); ops_decl_const2("rc3", 1, "double", &rc3); ops_decl_const2("nx0", 1, "int", &nx0); ops_decl_const2("deltai0", 1, "double", &deltai0); ops_decl_const2("deltat", 1, "double", &deltat); ops_block complex_numbers_block; complex_numbers_block = ops_decl_block(1, "complex_numbers_block"); ops_dat phi; ops_dat phi_old; ops_dat wk0; ops_dat wk1; int halo_p[] = {4}; int halo_m[] = {-4}; int size[] = {nx0}; int base[] = {0}; double *val = NULL; phi = ops_decl_dat(complex_numbers_block, 1, size, base, halo_m, halo_p, val, "double", "phi"); phi_old = ops_decl_dat(complex_numbers_block, 1, size, base, halo_m, halo_p, val, "double", "phi_old"); wk0 = ops_decl_dat(complex_numbers_block, 1, size, base, halo_m, halo_p, val, "double", "wk0"); wk1 = ops_decl_dat(complex_numbers_block, 1, size, base, halo_m, halo_p, val, "double", "wk1"); int stencil1_temp[] = {0}; ops_stencil stencil1 = ops_decl_stencil(1, 1, stencil1_temp, "0"); int stencil0_temp[] = {-4, -3, -2, -1, 1, 2, 3, 4}; ops_stencil stencil0 = ops_decl_stencil(1, 8, stencil0_temp, "-4,-3,-2,-1,1,2,3,4"); ops_reduction real = ops_decl_reduction_handle(sizeof(double), "double", "reduction_real"); ops_reduction imaginary = ops_decl_reduction_handle(sizeof(double), "double", "reduction_imaginary"); ops_halo_group halo_exchange0; { int halo_iter[] = {4}; int from_base[] = {0}; int to_base[] = {nx0}; int dir[] = {1}; ops_halo halo0 = ops_decl_halo(phi, phi, halo_iter, from_base, to_base, dir, dir); ops_halo grp[] = {halo0}; halo_exchange0 = ops_decl_halo_group(1, grp); } ops_halo_group halo_exchange1; { int halo_iter[] = {4}; int from_base[] = {nx0 - 4}; int to_base[] = {-4}; int dir[] = {1}; ops_halo halo0 = ops_decl_halo(phi, phi, halo_iter, from_base, to_base, dir, dir); ops_halo grp[] = {halo0}; halo_exchange1 = ops_decl_halo_group(1, grp); } ops_partition(""); int iter_range5[] = {-4, nx0 + 4}; ops_par_loop_complex_numbers_block0_5_kernel( "Initialisation", complex_numbers_block, 1, iter_range5, ops_arg_dat(phi, 1, stencil1, "double", OPS_WRITE), ops_arg_idx()); ops_halo_transfer(halo_exchange0); ops_halo_transfer(halo_exchange1); double cpu_start, elapsed_start; ops_timers(&cpu_start, &elapsed_start); for (int iteration = 0; iteration < 1; iteration++) { int iter_range4[] = {-4, nx0 + 4}; ops_par_loop_complex_numbers_block0_4_kernel( "Save equations", complex_numbers_block, 1, iter_range4, ops_arg_dat(phi, 1, stencil1, "double", OPS_READ), ops_arg_dat(phi_old, 1, stencil1, "double", OPS_WRITE)); for (int stage = 0; stage < 3; stage++) { int iter_range0[] = {0, nx0}; ops_par_loop_complex_numbers_block0_0_kernel( "D(phi[x0 t] x0)", complex_numbers_block, 1, iter_range0, ops_arg_dat(phi, 1, stencil0, "double", OPS_READ), ops_arg_dat(wk0, 1, stencil1, "double", OPS_WRITE)); int iter_range1[] = {0, nx0}; ops_par_loop_complex_numbers_block0_1_kernel( "Residual of equation", complex_numbers_block, 1, iter_range1, ops_arg_dat(wk0, 1, stencil1, "double", OPS_READ), ops_arg_dat(wk1, 1, stencil1, "double", OPS_WRITE)); int iter_range2[] = {-4, nx0 + 4}; ops_par_loop_complex_numbers_block0_2_kernel( "RK new (subloop) update", complex_numbers_block, 1, iter_range2, ops_arg_dat(phi_old, 1, stencil1, "double", OPS_READ), ops_arg_dat(wk1, 1, stencil1, "double", OPS_READ), ops_arg_dat(phi, 1, stencil1, "double", OPS_WRITE), ops_arg_gbl(&rknew[stage], 1, "double", OPS_READ)); int iter_range3[] = {-4, nx0 + 4}; ops_par_loop_complex_numbers_block0_3_kernel( "RK old update", complex_numbers_block, 1, iter_range3, ops_arg_dat(wk1, 1, stencil1, "double", OPS_READ), ops_arg_dat(phi_old, 1, stencil1, "double", OPS_RW), ops_arg_gbl(&rkold[stage], 1, "double", OPS_READ)); ops_halo_transfer(halo_exchange0); ops_halo_transfer(halo_exchange1); } int iter_range0[] = {0, nx0}; ops_par_loop_complex_numbers_block0_cn_kernel( "Complex numbers", complex_numbers_block, 1, iter_range0, ops_arg_dat(phi, 1, stencil0, "double", OPS_READ), ops_arg_reduce(real, 1, "double", OPS_INC), ops_arg_reduce(imaginary, 1, "double", OPS_INC)); } double cpu_end, elapsed_end; ops_timers(&cpu_end, &elapsed_end); ops_printf("\nTimings are:\n"); ops_printf("-----------------------------------------\n"); ops_printf("Total Wall time %lf\n", elapsed_end - elapsed_start); ops_fetch_block_hdf5_file(complex_numbers_block, "complex_numbers_2500.h5"); ops_fetch_dat_hdf5_file(phi, "complex_numbers_2500.h5"); ops_exit(); }
void calc_dt(double* local_dt, char* local_control, double* xl_pos, double* yl_pos, int* jldt, int* kldt) { int small; double jk_control = 1.1; small = 0; int dtl_control; //initialize sizes using global values int x_min = field.x_min; int x_max = field.x_max; int y_min = field.y_min; int y_max = field.y_max; int rangexy_inner[] = {x_min,x_max,y_min,y_max}; // inner range without border ops_par_loop(calc_dt_kernel, "calc_dt_kernel", clover_grid, 2, rangexy_inner, ops_arg_dat(celldx, 1, S2D_00_P10_STRID2D_X, "double", OPS_READ), ops_arg_dat(celldy, 1, S2D_00_0P1_STRID2D_Y, "double", OPS_READ), ops_arg_dat(soundspeed, 1, S2D_00, "double", OPS_READ), ops_arg_dat(viscosity, 1, S2D_00, "double", OPS_READ), ops_arg_dat(density0, 1, S2D_00, "double", OPS_READ), ops_arg_dat(xvel0, 1, S2D_00_P10_0P1_P1P1, "double", OPS_READ), ops_arg_dat(xarea, 1, S2D_00_P10, "double", OPS_READ), ops_arg_dat(volume, 1, S2D_00, "double", OPS_READ), ops_arg_dat(yvel0, 1, S2D_00_P10_0P1_P1P1, "double", OPS_READ), ops_arg_dat(yarea, 1, S2D_00_0P1, "double", OPS_READ), ops_arg_dat(work_array1, 1, S2D_00, "double", OPS_WRITE) ); ops_par_loop(calc_dt_kernel_min, "calc_dt_kernel_min", clover_grid, 2, rangexy_inner, ops_arg_dat(work_array1, 1, S2D_00, "double", OPS_READ), ops_arg_reduce(red_local_dt, 1, "double", OPS_MIN)); //printf("*local_dt = %lf\n",*local_dt); //Extract the mimimum timestep information dtl_control = 10.01 * (jk_control - (int)(jk_control)); jk_control = jk_control - (jk_control - (int)(jk_control)); //*jldt = ((int)jk_control)%x_max; //*kldt = 1 + (jk_control/x_max); *jldt = ((int)jk_control)%(x_max-2); *kldt = 1 + (jk_control/(x_max-2)); int rangexy_getpoint[] = {*jldt-1+2,*jldt+2,*kldt-1+2,*kldt+2}; // get point value //note +2 added due to boundary //int rangexy_getpointx[] = {*jldt-1+2,*jldt+2,y_min-2,y_max+2}; // get point value //note +2 added due to boundary //int rangexy_getpointy[] = {x_min-2,x_max+2,*kldt-1+2,*kldt+2}; // get point value //note +2 added due to boundary ops_par_loop(calc_dt_kernel_get, "calc_dt_kernel_getx", clover_grid, 2, rangexy_getpoint, ops_arg_dat(cellx, 1, S2D_00_STRID2D_X, "double", OPS_READ), ops_arg_dat(celly, 1, S2D_00_STRID2D_Y, "double", OPS_READ), ops_arg_reduce(red_xl_pos, 1, "double", OPS_INC), ops_arg_reduce(red_yl_pos, 1, "double", OPS_INC)); ops_reduction_result(red_local_dt, local_dt); ops_reduction_result(red_xl_pos, xl_pos); ops_reduction_result(red_yl_pos, yl_pos); *local_dt = MIN(*local_dt, g_big); if(*local_dt < dtmin) small = 1; if(small != 0) { ops_printf("Timestep information:\n"); ops_printf("j, k : %d, %d\n",*jldt,*kldt); ops_printf("x, y : %lf, %lf\n",*xl_pos,*xl_pos); ops_printf("timestep : %lf\n",*local_dt); double output[12] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}; ops_par_loop(calc_dt_kernel_print, "calc_dt_kernel_print", clover_grid, 2,rangexy_getpoint, ops_arg_dat(xvel0, 1, S2D_10_M10_01_0M1, "double", OPS_READ), ops_arg_dat(yvel0, 1, S2D_10_M10_01_0M1, "double", OPS_READ), ops_arg_dat(density0, 1, S2D_00, "double", OPS_READ), ops_arg_dat(energy0, 1, S2D_00, "double", OPS_READ), ops_arg_dat(pressure, 1, S2D_00, "double", OPS_READ), ops_arg_dat(soundspeed, 1, S2D_00, "double", OPS_READ), ops_arg_reduce(red_output, 12, "double", OPS_INC)); ops_reduction_result(red_output, output); ops_printf("Cell velocities:\n"); ops_printf("%E, %E \n",output[0],output[1]); //xvel0(jldt ,kldt ),yvel0(jldt ,kldt ) ops_printf("%E, %E \n",output[2],output[3]); //xvel0(jldt+1,kldt ),yvel0(jldt+1,kldt ) ops_printf("%E, %E \n",output[4],output[5]); //xvel0(jldt+1,kldt+1),yvel0(jldt+1,kldt+1) ops_printf("%E, %E \n",output[6],output[7]); //xvel0(jldt ,kldt+1),yvel0(jldt ,kldt+1) ops_printf("density, energy, pressure, soundspeed = %lf, %lf, %lf, %lf \n", output[8], output[9], output[10], output[11]); } if(dtl_control == 1) sprintf(local_control, "sound"); if(dtl_control == 2) sprintf(local_control, "xvel"); if(dtl_control == 3) sprintf(local_control, "yvel"); if(dtl_control == 4) sprintf(local_control, "div"); }
void read_input() { //some defailt values before read input test_problem = 0; state_max = 0; number_of_states = 0; //grid = (grid_type ) xmalloc(sizeof(grid_type_core)); grid.xmin = 0; grid.ymin = 0; grid.zmin = 0; grid.xmax = 100; grid.ymax = 100; grid.zmax = 100; grid.x_cells = 10; grid.y_cells = 10; grid.z_cells = 10; end_time = 10.0; end_step = g_ibig; complete = FALSE; visit_frequency=10; summary_frequency=10; dtinit = 0.1; dtmax = 1.0; dtmin = 0.0000001; dtrise = 1.05; dtc_safe = 0.75; dtu_safe = 0.5; dtv_safe = 0.5; dtw_safe = 0.5; dtdiv_safe = 0.5; use_vector_loops = TRUE; // //need to read in the following through I/O .. hard coded below // ops_fprintf(g_out," Reading input file\n"); #define LINESZ 1024 char buff[LINESZ]; FILE *fin = fopen ("clover.in", "r"); if (fin != NULL) { while (fgets (buff, LINESZ, fin)) { char* token = strtok(buff, " ="); while (token) { if(strcmp(token,"*clover\n") != 0 && strcmp(token,"*endclover\n") != 0 ) { //printf("token: %s ", token); if(strcmp(token,"initial_timestep") == 0) { token = strtok(NULL, " ="); dtinit = atof(token); ops_fprintf(g_out," %20s: %e\n", "initial_timestep",dtinit); } else if(strcmp(token,"max_timestep") == 0) { token = strtok(NULL, " ="); dtmax = atof(token); ops_fprintf(g_out," %20s: %e\n", "max_timestep",dtmax); } else if(strcmp(token,"timestep_rise") == 0) { token = strtok(NULL, " ="); dtrise = atof(token); ops_fprintf(g_out," %20s: %e\n", "timestep_rise",dtrise); } else if(strcmp(token,"end_time") == 0) { token = strtok(NULL, " ="); end_time = atof(token); ops_fprintf(g_out," %20s: %e\n", "end_time",end_time); } else if(strcmp(token,"end_step") == 0) { token = strtok(NULL, " ="); end_step = atof(token); ops_fprintf(g_out," %20s: %e\n", "end_step",end_step); } else if(strcmp(token,"xmin") == 0) { token = strtok(NULL, " ="); grid.xmin = atof(token); ops_fprintf(g_out," %20s: %e\n", "xmin",grid.xmin); } else if(strcmp(token,"xmax") == 0) { token = strtok(NULL, " ="); grid.xmax = atof(token); ops_fprintf(g_out," %20s: %e\n", "xmax",grid.xmax); } else if(strcmp(token,"ymin") == 0) { token = strtok(NULL, " ="); grid.ymin = atof(token); ops_fprintf(g_out," %20s: %e\n", "ymin",grid.ymin); } else if(strcmp(token,"ymax") == 0) { token = strtok(NULL, " ="); grid.ymax = atof(token); ops_fprintf(g_out," %20s: %e\n", "ymax",grid.ymax); } else if(strcmp(token,"zmin") == 0) { token = strtok(NULL, " ="); grid.zmin = atof(token); ops_fprintf(g_out," %20s: %e\n", "zmin",grid.zmin); } else if(strcmp(token,"zmax") == 0) { token = strtok(NULL, " ="); grid.zmax = atof(token); ops_fprintf(g_out," %20s: %e\n", "zmax",grid.zmax); } else if(strcmp(token,"x_cells") == 0) { token = strtok(NULL, " ="); grid.x_cells = atof(token); ops_fprintf(g_out," %20s: %d\n", "x_cells",grid.x_cells); } else if(strcmp(token,"y_cells") == 0) { token = strtok(NULL, " ="); grid.y_cells = atof(token); ops_fprintf(g_out," %20s: %d\n", "y_cells",grid.y_cells); } else if(strcmp(token,"z_cells") == 0) { token = strtok(NULL, " ="); grid.z_cells = atof(token); ops_fprintf(g_out," %20s: %d\n", "z_cells",grid.z_cells); } else if(strcmp(token,"visit_frequency") == 0) { token = strtok(NULL, " ="); visit_frequency = atoi(token); ops_fprintf(g_out," %20s: %d\n", "visit_frequency",visit_frequency); } else if(strcmp(token,"summary_frequency") == 0) { token = strtok(NULL, " ="); summary_frequency = atoi(token); ops_fprintf(g_out," %20s: %d\n", "summary_frequency",summary_frequency); } else if(strcmp(token,"test_problem") == 0) { token = strtok(NULL, " ="); test_problem = atoi(token); ops_fprintf(g_out," %20s: %d\n", "test_problem",test_problem); } else if(strcmp(token,"profiler_on") == 0) { token = strtok(NULL, " ="); profiler_on = atoi(token); ops_fprintf(g_out," %20s: %d\n", "profiler_on",profiler_on); } else if(strcmp(token,"state") == 0) { ops_fprintf(g_out,"\n"); ops_fprintf(g_out," Reading specification for state %d\n",number_of_states+1); ops_fprintf(g_out,"\n"); token = strtok(NULL, " ="); states = (state_type *) xrealloc(states, sizeof(state_type) * (number_of_states+1)); states[number_of_states].xvel = 0.0; states[number_of_states].yvel = 0.0; states[number_of_states].zvel = 0.0; token = strtok(NULL, " ="); while(token) { if(strcmp(token,"xvel") == 0) { token = strtok(NULL, " ="); states[number_of_states].xvel = atof(token); ops_fprintf(g_out,"xvel: %e\n", states[number_of_states].xvel); } if(strcmp(token,"yvel") == 0) { token = strtok(NULL, " ="); states[number_of_states].yvel = atof(token); ops_fprintf(g_out,"yvel: %e\n", states[number_of_states].yvel); } if(strcmp(token,"zvel") == 0) { token = strtok(NULL, " ="); states[number_of_states].zvel = atof(token); ops_fprintf(g_out,"zvel: %e\n", states[number_of_states].zvel); } if(strcmp(token,"xmin") == 0) { token = strtok(NULL, " ="); states[number_of_states].xmin = atof(token); ops_fprintf(g_out," %20s: %e\n","state xmin",states[number_of_states].xmin); } if(strcmp(token,"xmax") == 0) { token = strtok(NULL, " ="); states[number_of_states].xmax = atof(token); ops_fprintf(g_out," %20s: %e\n","state xmax",states[number_of_states].xmax); } if(strcmp(token,"ymin") == 0) { token = strtok(NULL, " ="); states[number_of_states].ymin = atof(token); ops_fprintf(g_out," %20s: %e\n","state ymin",states[number_of_states].ymin); } if(strcmp(token,"ymax") == 0) { token = strtok(NULL, " ="); states[number_of_states].ymax = atof(token); ops_fprintf(g_out," %20s: %e\n","state ymax",states[number_of_states].ymax); } if(strcmp(token,"zmin") == 0) { token = strtok(NULL, " ="); states[number_of_states].zmin = atof(token); ops_fprintf(g_out," %20s: %e\n","state zmin",states[number_of_states].zmin); } if(strcmp(token,"zmax") == 0) { token = strtok(NULL, " ="); states[number_of_states].zmax = atof(token); ops_fprintf(g_out," %20s: %e\n","state zmax",states[number_of_states].zmax); } if(strcmp(token,"density") == 0) { token = strtok(NULL, " ="); states[number_of_states].density = atof(token); ops_fprintf(g_out," %20s: %e\n", "state density",states[number_of_states].density); } if(strcmp(token,"energy") == 0) { token = strtok(NULL, " ="); states[number_of_states].energy = atof(token); ops_fprintf(g_out," %20s: %e\n", "state energy",states[number_of_states].energy); } if(strcmp(token,"geometry") == 0) { token = strtok(NULL, " ="); if(strcmp(token,"cuboid") == 0) { states[number_of_states].geometry = g_cube; ops_fprintf(g_out," %20s: %s\n","state geometry","cuboid"); } else if(strcmp(token,"sphere") == 0) { states[number_of_states].geometry = g_sphe; ops_fprintf(g_out," %20s: %s\n","state geometry","sphere"); } else if(strcmp(token,"point") == 0) { states[number_of_states].geometry = g_point; ops_fprintf(g_out," %20s: %s\n","state geometry","point"); } } token = strtok(NULL, " ="); } number_of_states++; ops_fprintf(g_out,"\n"); } } token = strtok(NULL, " ="); } } fclose (fin); } if(number_of_states == 0) { ops_printf("read_input, No states defined.\n"); exit(-1); } ops_fprintf(g_out,"\n"); ops_fprintf(g_out," Input read finished\n"); ops_fprintf(g_out,"\n"); //field = (field_type ) xmalloc(sizeof(field_type_core)); field.x_min = 0 +2; //+2 to account for the boundary field.y_min = 0 +2; //+2 to account for the boundary field.z_min = 0 +2; //+2 to account for the boundary field.x_max = grid.x_cells +2; //+2 to account for the boundary field.y_max = grid.y_cells +2; //+2 to account for the boundary field.z_max = grid.z_cells +2; //+2 to account for the boundary field.left = 0; field.bottom = 0; field.back = 0; float dx= (grid.xmax-grid.xmin)/(float)(grid.x_cells); float dy= (grid.ymax-grid.ymin)/(float)(grid.y_cells); float dz= (grid.zmax-grid.zmin)/(float)(grid.z_cells); for(int i = 0; i < number_of_states; i++) { states[i].xmin = states[i].xmin + (dx/100.00); states[i].ymin = states[i].ymin + (dy/100.00); states[i].zmin = states[i].zmin + (dz/100.00); states[i].xmax = states[i].xmax - (dx/100.00); states[i].ymax = states[i].ymax - (dy/100.00); states[i].zmax = states[i].zmax - (dz/100.00); } }
int main(int argc, char **argv) { /**-------------------------- Initialisation --------------------------**/ // OPS initialisation ops_init(argc,argv,6); int logical_size_x = 200; int logical_size_y = 200; int ngrid_x = 1; int ngrid_y = 1; int n_iter = 10000; dx = 0.01; dy = 0.01; ops_decl_const("dx",1,"double",&dx); ops_decl_const("dy",1,"double",&dy); //declare blocks ops_block *blocks = (ops_block *)malloc(ngrid_x*ngrid_y*sizeof(ops_block*)); char buf[50]; for (int j = 0; j < ngrid_y; j++) { for (int i = 0; i < ngrid_x; i++) { sprintf(buf,"block %d,%d",i,j); blocks[i+ngrid_x*j] = ops_decl_block(2,buf); } } //declare stencils int s2D_00[] = {0,0}; ops_stencil S2D_00 = ops_decl_stencil( 2, 1, s2D_00, "00"); int s2D_00_P10_M10_0P1_0M1[] = {0,0, 1,0, -1,0, 0,1, 0,-1}; ops_stencil S2D_00_P10_M10_0P1_0M1 = ops_decl_stencil( 2, 5, s2D_00_P10_M10_0P1_0M1, "00:10:-10:01:0-1"); ops_reduction red_err = ops_decl_reduction_handle(sizeof(double), "double", "err"); //declare datasets int d_p[2] = {1,1}; //max halo depths for the dat in the possitive direction int d_m[2] = {-1,-1}; //max halo depths for the dat in the negative direction int base[2] = {0,0}; int uniform_size[2] = {(logical_size_x-1)/ngrid_x+1,(logical_size_y-1)/ngrid_y+1}; double* temp = NULL; ops_dat *coordx = (ops_dat *)malloc(ngrid_x*ngrid_y*sizeof(ops_dat*)); ops_dat *coordy = (ops_dat *)malloc(ngrid_x*ngrid_y*sizeof(ops_dat*)); ops_dat *u = (ops_dat *)malloc(ngrid_x*ngrid_y*sizeof(ops_dat*)); ops_dat *u2 = (ops_dat *)malloc(ngrid_x*ngrid_y*sizeof(ops_dat*)); ops_dat *f = (ops_dat *)malloc(ngrid_x*ngrid_y*sizeof(ops_dat*)); ops_dat *ref = (ops_dat *)malloc(ngrid_x*ngrid_y*sizeof(ops_dat*)); int *sizes = (int*)malloc(2*ngrid_x*ngrid_y*sizeof(int)); int *disps = (int*)malloc(2*ngrid_x*ngrid_y*sizeof(int)); for (int j = 0; j < ngrid_y; j++) { for (int i = 0; i < ngrid_x; i++) { int size[2] = {uniform_size[0], uniform_size[1]}; if ((i+1)*size[0]>logical_size_x) size[0] = logical_size_x - i*size[0]; if ((j+1)*size[1]>logical_size_y) size[1] = logical_size_y - j*size[1]; sprintf(buf,"coordx %d,%d",i,j); coordx[i+ngrid_x*j] = ops_decl_dat(blocks[i+ngrid_x*j], 1, size, base, d_m, d_p, temp, "double", buf); sprintf(buf,"coordy %d,%d",i,j); coordy[i+ngrid_x*j] = ops_decl_dat(blocks[i+ngrid_x*j], 1, size, base, d_m, d_p, temp, "double", buf); sprintf(buf,"u %d,%d",i,j); u[i+ngrid_x*j] = ops_decl_dat(blocks[i+ngrid_x*j], 1, size, base, d_m, d_p, temp, "double", buf); sprintf(buf,"u2 %d,%d",i,j); u2[i+ngrid_x*j] = ops_decl_dat(blocks[i+ngrid_x*j], 1, size, base, d_m, d_p, temp, "double", buf); sprintf(buf,"f %d,%d",i,j); f[i+ngrid_x*j] = ops_decl_dat(blocks[i+ngrid_x*j], 1, size, base, d_m, d_p, temp, "double", buf); sprintf(buf,"ref %d,%d",i,j); ref[i+ngrid_x*j] = ops_decl_dat(blocks[i+ngrid_x*j], 1, size, base, d_m, d_p, temp, "double", buf); sizes[2*(i+ngrid_x*j)] = size[0]; sizes[2*(i+ngrid_x*j)+1] = size[1]; disps[2*(i+ngrid_x*j)] = i*uniform_size[0]; disps[2*(i+ngrid_x*j)+1] = j*uniform_size[1]; } } ops_halo *halos = (ops_halo *)malloc(2*(ngrid_x*(ngrid_y-1)+(ngrid_x-1)*ngrid_y)*sizeof(ops_halo *)); int off = 0; for (int j = 0; j < ngrid_y; j++) { for (int i = 0; i < ngrid_x; i++) { if (i > 0) { int halo_iter[] = {1,sizes[2*(i+ngrid_x*j)+1]}; int base_from[] = {sizes[2*(i-1+ngrid_x*j)]-1,0}; int base_to[] = {-1,0}; int dir[] = {1,2}; halos[off++] = ops_decl_halo(u[i-1+ngrid_x*j], u[i+ngrid_x*j], halo_iter, base_from, base_to, dir, dir); base_from[0] = 0; base_to[0] = sizes[2*(i+ngrid_x*j)]; halos[off++] = ops_decl_halo(u[i+ngrid_x*j], u[i-1+ngrid_x*j], halo_iter, base_from, base_to, dir, dir); } if (j > 0) { int halo_iter[] = {sizes[2*(i+ngrid_x*j)],1}; int base_from[] = {0,sizes[2*(i+ngrid_x*(j-1))+1]-1}; int base_to[] = {0,-1}; int dir[] = {1,2}; halos[off++] = ops_decl_halo(u[i+ngrid_x*(j-1)], u[i+ngrid_x*j], halo_iter, base_from, base_to, dir, dir); base_from[1] = 0; base_to[1] = sizes[2*(i+ngrid_x*j)+1]; halos[off++] = ops_decl_halo(u[i+ngrid_x*j], u[i+ngrid_x*(j-1)], halo_iter, base_from, base_to, dir, dir); } } } if (off != 2*(ngrid_x*(ngrid_y-1)+(ngrid_x-1)*ngrid_y)) printf("Something is not right\n"); ops_halo_group u_halos = ops_decl_halo_group(off,halos); ops_partition(""); ops_checkpointing_init("check.h5", 5.0); /**-------------------------- Computations --------------------------**/ double ct0, ct1, et0, et1; ops_timers_core(&ct0, &et0); //populate forcing, reference solution and boundary conditions for (int j = 0; j < ngrid_y; j++) { for (int i = 0; i < ngrid_x; i++) { int iter_range[] = {-1,sizes[2*(i+ngrid_x*j)]+1,-1,sizes[2*(i+ngrid_x*j)+1]+1}; ops_par_loop(poisson_kernel_populate, "poisson_kernel_populate", blocks[i+ngrid_x*j], 2, iter_range, ops_arg_gbl(&disps[2*(i+ngrid_x*j)], 1, "int", OPS_READ), ops_arg_gbl(&disps[2*(i+ngrid_x*j)+1], 1, "int", OPS_READ), ops_arg_idx(), ops_arg_dat(u[i+ngrid_x*j], S2D_00, "double", OPS_WRITE), ops_arg_dat(f[i+ngrid_x*j], S2D_00, "double", OPS_WRITE), ops_arg_dat(ref[i+ngrid_x*j], S2D_00, "double", OPS_WRITE)); } } //initial guess 0 for (int j = 0; j < ngrid_y; j++) { for (int i = 0; i < ngrid_x; i++) { int iter_range[] = {0,sizes[2*(i+ngrid_x*j)],0,sizes[2*(i+ngrid_x*j)+1]}; ops_par_loop(poisson_kernel_initialguess, "poisson_kernel_initialguess", blocks[i+ngrid_x*j], 2, iter_range, ops_arg_dat(u[i+ngrid_x*j], S2D_00, "double", OPS_WRITE)); } } for (int iter = 0; iter < n_iter; iter++) { ops_halo_transfer(u_halos); for (int j = 0; j < ngrid_y; j++) { for (int i = 0; i < ngrid_x; i++) { int iter_range[] = {0,sizes[2*(i+ngrid_x*j)],0,sizes[2*(i+ngrid_x*j)+1]}; ops_par_loop(poisson_kernel_stencil, "poisson_kernel_stencil", blocks[i+ngrid_x*j], 2, iter_range, ops_arg_dat(u[i+ngrid_x*j], S2D_00_P10_M10_0P1_0M1, "double", OPS_READ), ops_arg_dat(f[i+ngrid_x*j], S2D_00, "double", OPS_READ), ops_arg_dat(u2[i+ngrid_x*j], S2D_00, "double", OPS_WRITE)); } } for (int j = 0; j < ngrid_y; j++) { for (int i = 0; i < ngrid_x; i++) { int iter_range[] = {0,sizes[2*(i+ngrid_x*j)],0,sizes[2*(i+ngrid_x*j)+1]}; ops_par_loop(poisson_kernel_update, "poisson_kernel_update", blocks[i+ngrid_x*j], 2, iter_range, ops_arg_dat(u2[i+ngrid_x*j], S2D_00, "double", OPS_READ), ops_arg_dat(u[i+ngrid_x*j] , S2D_00, "double", OPS_WRITE)); } } } double err = 0.0; for (int j = 0; j < ngrid_y; j++) { for (int i = 0; i < ngrid_x; i++) { int iter_range[] = {0,sizes[2*(i+ngrid_x*j)],0,sizes[2*(i+ngrid_x*j)+1]}; ops_par_loop(poisson_kernel_error, "poisson_kernel_error", blocks[i+ngrid_x*j], 2, iter_range, ops_arg_dat(u[i+ngrid_x*j], S2D_00, "double", OPS_READ), ops_arg_dat(ref[i+ngrid_x*j] , S2D_00, "double", OPS_READ), ops_arg_reduce(red_err, 1, "double", OPS_INC)); } } ops_reduction_result(red_err,&err); ops_printf("Total error: %g\n",err); ops_timers_core(&ct1, &et1); ops_timing_output(); ops_printf("\nTotal Wall time %lf\n",et1-et0); ops_exit(); }
void field_summary() { double qa_diff; int x_min = field.x_min; int x_max = field.x_max; int y_min = field.y_min; int y_max = field.y_max; int z_min = field.z_min; int z_max = field.z_max; int rangexyz_inner[] = {x_min, x_max, y_min, y_max, z_min, z_max}; ideal_gas(FALSE); double vol = 0.0, mass = 0.0, ie = 0.0, ke = 0.0, press = 0.0; ops_par_loop_field_summary_kernel( "field_summary_kernel", clover_grid, 3, rangexyz_inner, ops_arg_dat(volume, 1, S3D_000, "double", OPS_READ), ops_arg_dat(density0, 1, S3D_000, "double", OPS_READ), ops_arg_dat(energy0, 1, S3D_000, "double", OPS_READ), ops_arg_dat(pressure, 1, S3D_000, "double", OPS_READ), ops_arg_dat(xvel0, 1, S3D_000_fP1P1P1, "double", OPS_READ), ops_arg_dat(yvel0, 1, S3D_000_fP1P1P1, "double", OPS_READ), ops_arg_dat(zvel0, 1, S3D_000_fP1P1P1, "double", OPS_READ), ops_arg_reduce(red_vol, 1, "double", OPS_INC), ops_arg_reduce(red_mass, 1, "double", OPS_INC), ops_arg_reduce(red_ie, 1, "double", OPS_INC), ops_arg_reduce(red_ke, 1, "double", OPS_INC), ops_arg_reduce(red_press, 1, "double", OPS_INC)); ops_reduction_result(red_vol, &vol); ops_reduction_result(red_mass, &mass); ops_reduction_result(red_ie, &ie); ops_reduction_result(red_ke, &ke); ops_reduction_result(red_press, &press); ops_fprintf(g_out, "\n"); ops_fprintf(g_out, "\n Time %lf\n", clover_time); ops_fprintf(g_out, " %-10s %-10s %-10s %-10s %-15s %-15s %-s\n", " Volume", " Mass", " Density", " Pressure", " Internal Energy", "Kinetic Energy", "Total Energy"); ops_fprintf(g_out, " step: %3d %-10.3E %-10.3E %-10.3E %-10.3E " "%-15.3E %-15.3E %-.3E", step, vol, mass, mass / vol, press / vol, ie, ke, ie + ke); if (complete == TRUE && test_problem) { qa_diff = DBL_MAX; if (test_problem == 1) qa_diff = fabs((100.0 * (ke / 3.64560737191257)) - 100.0); if (test_problem == 2) qa_diff = fabs((100.0 * (ke / 20.0546870878964)) - 100.0); if (test_problem == 3) qa_diff = fabs((100.0 * (ke / 0.37517221925665)) - 100.0); if (test_problem == 4) qa_diff = fabs((100.0 * (ke / 17.9845165368889)) - 100.0); if (test_problem == 5) qa_diff = fabs((100.0 * (ke / 2.05018938455107)) - 100.0); ops_printf( "\n\nTest problem %d is within %3.15E %% of the expected solution\n", test_problem, qa_diff); ops_fprintf( g_out, "\n\nTest problem %d is within %3.15E %% of the expected solution\n", test_problem, qa_diff); if (qa_diff < 0.001) { ops_printf("This test is considered PASSED\n"); ops_fprintf(g_out, "This test is considered PASSED\n"); } else { ops_printf("This test is considered FAILED\n"); ops_fprintf(g_out, "This test is considered FAILED\n"); } } fflush(g_out); }