#ifdef __cplusplus extern "C" { #endif //========================================================================================================================================================================================================200 //======================================================================================================================================================150 //====================================================================================================100 //==================================================50 //========================================================================================================================================================================================================200 // INFORMATION //========================================================================================================================================================================================================200 //======================================================================================================================================================150 // UPDATE //======================================================================================================================================================150 // 2009.12 Lukasz G. Szafaryn // -- entire code written //======================================================================================================================================================150 // DESCRIPTION //======================================================================================================================================================150 // Description //======================================================================================================================================================150 // USE //======================================================================================================================================================150 // How to run //========================================================================================================================================================================================================200 // DEFINE/INCLUDE //========================================================================================================================================================================================================200 //======================================================================================================================================================150 // LIBRARIES //======================================================================================================================================================150 #include // (in path known to compiler) needed by printf #include // (in path known to compiler) needed by malloc #include // (in path known to compiler) needed by true/false //======================================================================================================================================================150 // UTILITIES //======================================================================================================================================================150 #include "./util/timer/timer.h" // (in path specified here) #include "./util/num/num.h" // (in path specified here) //======================================================================================================================================================150 // MAIN FUNCTION HEADER //======================================================================================================================================================150 #include "./main.h" // (in the current directory) //======================================================================================================================================================150 // KERNEL //======================================================================================================================================================150 #include "./kernel/kernel_gpu_opencl_wrapper.h" // (in library path specified here) // Helper function to print usage void usage(char *argv0) { char *help = "\nUsage: %s [switches] \n\n" " -b :number of boxes [default=0]\n" " -p platform_id :OCL platform to use [default=0]\n" " -d device_id :OCL device to use [default=0]\n" " -g use_gpu :1 for GPU 0 for CPU [default=0]\n"; fprintf(stderr, help, argv0); exit(-1); } //========================================================================================================================================================================================================200 // MAIN FUNCTION //========================================================================================================================================================================================================200 int main( int argc, char *argv []) { //======================================================================================================================================================150 // CPU/MCPU VARIABLES //======================================================================================================================================================150 // timer long long time0; time0 = get_time(); // timer long long time1; long long time2; long long time3; long long time4; long long time5; long long time6; long long time7; // counters int i, j, k, l, m, n; // system memory par_str par_cpu; dim_str dim_cpu; box_str* box_cpu; FOUR_VECTOR* rv_cpu; fp* qv_cpu; FOUR_VECTOR* fv_cpu; int nh; printf("WG size of kernel = %d \n", NUMBER_THREADS); time1 = get_time(); //======================================================================================================================================================150 // CHECK INPUT ARGUMENTS //======================================================================================================================================================150 // assing default values dim_cpu.arch_arg = 0; dim_cpu.cores_arg = 1; dim_cpu.boxes1d_arg = 1; /*// go through arguments if(argc>=3){ for(dim_cpu.cur_arg=1; dim_cpu.cur_arg=dim_cpu.cur_arg+1){ // check if value is a number if(isInteger(argv[dim_cpu.cur_arg+1])==1){ dim_cpu.boxes1d_arg = atoi(argv[dim_cpu.cur_arg+1]); if(dim_cpu.boxes1d_arg<0){ printf("ERROR: Wrong value to -boxes1d argument, cannot be <=0\n"); return 0; } dim_cpu.cur_arg = dim_cpu.cur_arg+1; } // value is not a number else{ printf("ERROR: Value to -boxes1d argument in not a number\n"); return 0; } } // value not provided else{ printf("ERROR: Missing value to -boxes1d argument\n"); return 0; } } // unknown else{ printf("ERROR: Unknown argument\n"); return 0; } } // Print configuration printf("Configuration used: arch = %d, cores = %d, boxes1d = %d\n", dim_cpu.arch_arg, dim_cpu.cores_arg, dim_cpu.boxes1d_arg); } else{ printf("Provide boxes1d argument, example: -boxes1d 16"); return 0; }*/ // Arguments parsing for platform, device and type // Variables to store information on platform and device to use_gpu int platform_id = 0; int device_id = 0; int use_gpu = 0; /* obtain command line arguments and change appropriate options */ int opt; extern char *optarg; while ((opt=getopt(argc,argv,"b:p:d:g:"))!= EOF) { switch (opt) { case 'p': platform_id = atoi(optarg); break; case 'd': device_id = atoi(optarg); break; case 'g': use_gpu = atoi(optarg); break; case 'b': dim_cpu.boxes1d_arg = atoi(optarg); break; case '?': usage(argv[0]); break; default: usage(argv[0]); break; } } time2 = get_time(); //======================================================================================================================================================150 // INPUTS //======================================================================================================================================================150 par_cpu.alpha = 0.5; time3 = get_time(); //======================================================================================================================================================150 // DIMENSIONS //======================================================================================================================================================150 // total number of boxes dim_cpu.number_boxes = dim_cpu.boxes1d_arg * dim_cpu.boxes1d_arg * dim_cpu.boxes1d_arg; // 8*8*8=512 // how many particles space has in each direction dim_cpu.space_elem = dim_cpu.number_boxes * NUMBER_PAR_PER_BOX; //512*100=51,200 dim_cpu.space_mem = dim_cpu.space_elem * sizeof(FOUR_VECTOR); dim_cpu.space_mem2 = dim_cpu.space_elem * sizeof(fp); // box array dim_cpu.box_mem = dim_cpu.number_boxes * sizeof(box_str); time4 = get_time(); //======================================================================================================================================================150 // SYSTEM MEMORY //======================================================================================================================================================150 //====================================================================================================100 // BOX //====================================================================================================100 // allocate boxes box_cpu = (box_str*)malloc(dim_cpu.box_mem); // initialize number of home boxes nh = 0; // home boxes in z direction for(i=0; i=0 && (j+m)>=0 && (k+n)>=0)==true && ((i+l)