#include #include #include #include #include #include #include #include #include #ifdef __APPLE_CC__ #include #else #include #endif using namespace std; namespace xppc{ #define OFLA // omit the flasher DOM #define ROMB // use rhomb cells aligned with the array #define ASENS // enable angular sensitivity #define RAND // disable for deterministic results #define TILT // enable tilted ice layers #define ANIZ // enable anisotropic ice #define MKOW // photon yield parametrizations by M. Kowalski #define ANGW // smear cherenkov cone due to shower development #define LONG // simulate longitudinal cascade development #define CWLR // new parameterizations by C. Wiebusch and L. Raedel // requires that MKOW, ANGW, and LONG are all defined #ifdef ASENS #define ANUM 11 // number of coefficients in the angular sensitivity curve #endif #ifdef TILT #define LMAX 6 // number of dust loggers #define LYRS 170 // number of depth points #endif #ifdef ROMB #define DIR1 9.3 #define DIR2 129.3 #define CX 21 #define CY 19 #define NSTR 94 #else #define CX 13 #define CY 13 #define NSTR 94 #endif #define OVER 10 // size of photon bunches along the muon track #define HQUO 16 // save at most photons/HQUO hits #define NPHO 1024 // maximum number of photons propagated by one thread #define WNUM 32 // number of wavelength slices #define MAXLYS 172 // maximum number of ice layers #define MAXGEO 5200 // maximum number of OMs #define MAXRND 16028 // maximum number of random number multipliers #define XXX 1.e-5f #define FPI 3.141592653589793f #define OMR 0.16510f // DOM radius [m] #include "pro.cxx" #include "ini.cxx" #define SHRT #include "pro.cxx" #undef SHRT void initialize(float enh = 1.f){ m.set(); d.eff*=enh; } unsigned int pmax, pmxo, pn; size_t nblk, nthr, ntot; void ini(){ rs_ini(); ntot=nblk*nthr; pmax=ntot*NPHO; pmxo=pmax/OVER; pmax=pmxo*OVER; d.hnum=pmax/HQUO; pn=0; } float deviceTime=0; cl_event event; cl_platform_id pfID; cl_device_id devID; cl_context ctx; cl_command_queue cq; cl_program program; cl_kernel clkernel; cl_mem ed, ez, eh, ep, eo; // pointers to structures on device void checkError(cl_int result){ if(result!=CL_SUCCESS){ cerr<<"OpenCL Error: "<0){ checkError(clEnqueueReadBuffer(cq, ed, CL_TRUE, 0, 2*sizeof(int), &d, 0, NULL, NULL)); cl_ulong t1, t2; checkError(clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &t1, NULL)); checkError(clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &t2, NULL)); deviceTime+=(long long)(t2-t1)/1.e6; if(d.ab>0) cerr<<"Error: TOT was a nan or an inf "<=d.hnum){ d.hidx=d.hnum; cerr<<"Error: data buffer overflow occurred!"<0){ unsigned int size=d.hidx*sizeof(hit); checkError(clEnqueueReadBuffer(cq, eh, CL_FALSE, 0, size, q.hits, 0, NULL, NULL)); } } if(d.type==0){ unsigned int pn=num/OVER; if(old>0) checkError(clFinish(cq)); if(pn>0){ unsigned int size=pn*sizeof(photon); checkError(clEnqueueWriteBuffer(cq, ep, CL_FALSE, 0, size, q.pz, 0, NULL, NULL)); } } checkError(clFinish(cq)); if(num>0){ unsigned int zero=0; checkError(clSetKernelArg(clkernel, 0, sizeof(unsigned int), &zero)); checkError(clEnqueueTask(cq, clkernel, 0, NULL, NULL)); checkError(clSetKernelArg(clkernel, 0, sizeof(unsigned int), &num)); checkError(clEnqueueNDRangeKernel(cq, clkernel, 1, NULL, &ntot, &nthr, 0, NULL, &event)); } if(old>0) print(); old=num; } void flini(int str, int dom){ int type=1; float r[3]={0, 0, 0}; if(str<0){ type=2; str=-str; } if(str==0) switch(dom){ case 1: type=3; r[0]=544.07; r[1]=55.89; r[2]=136.86; break; case 2: type=4; r[0]=11.87; r[1]=179.19; r[2]=-205.64; break; } else for(int n=0; n0; i-=pmax) kernel(min(i, (long long) pmax)); kernel(0); } void flasher(int str, int dom, unsigned long long num, int itr){ flini(str, dom); for(int j=0; j0) printf("\n"); } fin(); } void start(){ } void stop(){ fprintf(stderr, "\nDevice time: %2.1f [ms]\n", deviceTime); if(clkernel) checkError(clReleaseKernel(clkernel)); if(program) checkError(clReleaseProgram(program)); if(cq) checkError(clReleaseCommandQueue(cq)); if(ctx) checkError(clReleaseContext(ctx)); } string& replace(string& in, string old, string str){ string clx; int k=0, m=0; while((m=in.find(old, k))!=-1){ clx.append(in, k, m-k); k=m+old.length(); clx.append(str); } clx.append(in, k, in.length()-k); return in=clx; } void choose(int device){ sv+=device; if(!listDevices(device)){ cerr<<"Device #"<1) device=atoi(arg_a[1]); initialize(); choose(device); fprintf(stderr, "Processing f2k muons from stdin on device %d\n", device); f2k(); } else{ int str=0, dom=0, device=0, itr=0; unsigned long long num=1000000ULL; if(arg_c>1) str=atoi(arg_a[1]); if(arg_c>2) dom=atoi(arg_a[2]); if(arg_c>3){ num=(unsigned long long) atof(arg_a[3]); char * sub = strchr(arg_a[3], '*'); if(sub!=NULL) itr=(int) atof(++sub); } if(arg_c>4) device=atoi(arg_a[4]); initialize(); choose(device); fprintf(stderr, "Running flasher simulation on device %d\n", device); flasher(str, dom, num, itr); } stop(); } #endif