#include #include "ini.h" #include "pro.cu" extern dats d; dats e=d; // copy of "d" for device dats *ed; // pointer to structure on device static const unsigned long long pmax=(unsigned long long)NPHO*NBLK*NTHR; unsigned long long pn; photon * pz; unsigned int mode=0, fsim=0; float deviceTime=0; void checkError(cudaError result){ if(result!=cudaSuccess){ fprintf(stderr, "Error: %s\n", cudaGetErrorString(result)); exit(1); } } void ini(int type){ { pn=0; fsim=type; e.type=type; e.hidx=0; for(int m=0; m<3; m++) e.r[m]=0; } { unsigned int size=d.rsize; if(size0&&mode>0?WNUM:NBLK, NTHR >>>(ed, num); checkError(cudaGetLastError()); checkError(cudaEventRecord(evt2, NULL)); checkError(cudaEventSynchronize(evt2)); checkError(cudaEventElapsedTime(&dt, evt1, evt2)); deviceTime+=dt; checkError(cudaEventDestroy(evt1)); checkError(cudaEventDestroy(evt2)); checkError(cudaThreadSynchronize()); } { checkError(cudaMemcpy(&e, ed, sizeof(int), cudaMemcpyDeviceToHost)); unsigned int size=e.hidx*sizeof(hit); checkError(cudaMemcpy(d.hits, e.hits, size, cudaMemcpyDeviceToHost)); } if(fsim==0||mode==0) fprintf(stderr, "photons: %llu hits: %u\n", num, e.hidx); for(int i=0; i=e.hnum) fprintf(stderr, "Error: data buffer overflow occurred!\n"); } void flasher(int str, int dom, unsigned long long num){ ini(0); for(long long i=num; i>0; i-=pmax){ e.hidx=0; for(int n=0; n0){ sscanf(line, "%31s", name); if(0==strcmp(name, "EE")) output(); } printf("%s\n", line); int gens, igen; float x, y, z, th, ph, l, E, t; char * str = "TR %d %d %31s %f %f %f %f %f %f %f %f"; if(sscanf(line, str, &gens, &igen, &name, &x, &y, &z, &th, &ph, &l, &E, &t)==11){ th=180-th; ph=ph<180?ph+180:ph-180; th*=M_PI/180; ph*=M_PI/180; float costh=cosf(th), sinth=sinf(th), cosph=cosf(ph), sinph=sinf(ph); p.n[0]=sinth*cosph; p.n[1]=sinth*sinph; p.n[2]=costh; if(0==strcmp(name, "amu+") || 0==strcmp(name, "amu-") || 0==strcmp(name, "amu")) muon(x, y, z, t, E, l); else if(0==strcmp(name, "delta") || 0==strcmp(name, "brems") || 0==strcmp(name, "epair") || 0==strcmp(name, "e+") || 0==strcmp(name, "e-") || 0==strcmp(name, "e")) cascade(x, y, z, t, E, 0); else if(0==strcmp(name, "munu") || 0==strcmp(name, "hadr")) cascade(x, y, z, t, E, 1); } } output(); fin(); } int main(int arg_c, char *arg_a[]){ cudaSetDeviceFlags(cudaDeviceBlockingSync); if(arg_c<=1){ listDevices(); fprintf(stderr, "\nUse: %s [device] [mode] (f2k muons)\n" " %s [str] [om] [num] [device] [mode] (flasher)\n", arg_a[0], arg_a[0]); } else if(arg_c<=3){ int device=0; if(arg_c>1) device=atoi(arg_a[1]); if(arg_c>2) mode=atoi(arg_a[2]); checkError(cudaSetDevice(device)); fprintf(stderr, "Processing f2k muons from stdin on device %d\n", device); f2k(); } else{ int str=0, dom=0, device=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]); if(arg_c>4) device=atoi(arg_a[4]); if(arg_c>5) mode=atoi(arg_a[5]); checkError(cudaSetDevice(device)); fprintf(stderr, "Running flasher simulation on device %d\n", device); flasher(str, dom, num); } fprintf(stderr, "\nDevice time: %2.1f [ms]\n", deviceTime); checkError(cudaThreadExit()); }