#include #include #include #include using namespace std; #include "ini.cxx" #include "pro.cu" dats e=d; // copy of "d" for device dats *ed; // pointer to structure on device unsigned int pmax, pn; photon * pz; float deviceTime=0; cudaDeviceProp prop; int nblk; void checkError(cudaError result){ if(result!=cudaSuccess){ cerr<<"Error: "<>>(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)); } cerr<<"photons: "<=e.hnum) cerr<<"Error: data buffer overflow occurred!"<0; i-=pmax){ if(i0) printf("\n"); } fin(); } void output(){ { e.hidx=0; checkError(cudaMemcpy(ed, &e, sizeof(int), cudaMemcpyHostToDevice)); } { unsigned int size=pn*sizeof(photon); checkError(cudaMemcpy(e.pz, pz, size, cudaMemcpyHostToDevice)); } kernel(pn); pn=0; } int main(int arg_c, char *arg_a[]){ cudaSetDeviceFlags(cudaDeviceBlockingSync); if(arg_c<=1){ listDevices(); fprintf(stderr, "\nUse: %s [device] (f2k muons)\n" " %s [str] [om] [num] [device] (flasher)\n", arg_a[0], arg_a[0]); } else if(arg_c<=2){ int device=0; if(arg_c>1) device=atoi(arg_a[1]); checkError(cudaSetDevice(device)); checkError(cudaGetDeviceProperties(&prop, 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]); checkError(cudaSetDevice(device)); checkError(cudaGetDeviceProperties(&prop, device)); fprintf(stderr, "Running flasher simulation on device %d\n", device); flasher(str, dom, num, itr); } fprintf(stderr, "\nDevice time: %2.1f [ms]\n", deviceTime); checkError(cudaThreadExit()); }