diff --git a/README.md b/README.md index 98fb2e33..743a78a3 100644 --- a/README.md +++ b/README.md @@ -119,16 +119,7 @@ If it runs with no errors, then you should be all set up! Compiling After Changes ========== Every time you change the source code of G4STORK or GEANT4, you need to -recompile. From `/path/to/GEANT4-GPU/G4STORK/Build` run the recompile script to -recompile the project with: -``` -./addfilesG4STORK -``` -You can optionally add arguments when running the script, open it in a text -editor to see available arguments. - -Once that is done, the g4stork executable should be updated to include the -changes to your code. +recompile. From `/path/to/GEANT4-GPU/geant4.10.00.p02-build` rerun the cmake command from *Install GEANT-4: Step 4*, run `make`, and then run `make install`. Note that you only need to rerun cmake if you modified any CMake files, but you must always run the two make commands. Troubleshooting ========== diff --git a/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/cuda/CMakeLists.txt b/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/cuda/CMakeLists.txt index 9287f6dd..50b4c029 100644 --- a/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/cuda/CMakeLists.txt +++ b/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/cuda/CMakeLists.txt @@ -10,4 +10,6 @@ if (GEANT4_ENABLE_CUDA) LIST(APPEND CUDA_NVCC_FLAGS --compiler-options -fno-strict-aliasing -lineinfo -use_fast_math -Xptxas -dlcm=cg) LIST(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_30,code=sm_30) + + target_link_libraries(CUDA_G4NeutronHPVector ${GEANT4_LIBRARIES}) endif() \ No newline at end of file diff --git a/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/sources.cmake b/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/sources.cmake index f4b31e1e..50e60519 100644 --- a/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/sources.cmake +++ b/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/sources.cmake @@ -16,7 +16,7 @@ #----------------------------------------------------------------------- # Include CUDA -include_directories(cuda) +include_directories(${CMAKE_SOURCE_DIR}/source/processes/hadronic/models/neutron_hp/cuda) # List external includes needed. include_directories(${CLHEP_INCLUDE_DIRS}) @@ -311,7 +311,6 @@ GEANT4_DEFINE_MODULE(NAME G4had_neu_hp G4WendtFissionFragmentGenerator.cc ### Fission Fragment Generator - end GRANULAR_DEPENDENCIES - #CUDA_G4NeutronHPVector G4baryons G4bosons G4geometrymng @@ -342,6 +341,14 @@ GEANT4_DEFINE_MODULE(NAME G4had_neu_hp G4track LINK_LIBRARIES #CUDA_G4NeutronHPVector + # if uncommented, then when running hadr04 we get error: + # === + # dyld: Library not loaded: libCUDA_G4NeutronHPVector.dylib + # Referenced from: /Users/stuart/Documents/4th_Year/CS_4ZP6/GEANT4-GPU/geant4.10.00.p02-install/lib/libG4Tree.dylib + # Reason: image not found + # Trace/BPT trap: 5 + # === + ${ZLIB_LIBRARIES} ) diff --git a/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/src/G4NeutronHPVector.cc b/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/src/G4NeutronHPVector.cc index 57561211..6565f3ad 100644 --- a/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/src/G4NeutronHPVector.cc +++ b/geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/src/G4NeutronHPVector.cc @@ -33,14 +33,16 @@ #include "G4NeutronHPVector.hh" #include "G4SystemOfUnits.hh" - -//#if GEANT4_CUDA_ENABLED -// #include "CUDA_G4NeutronHPVector.h" -//#endif + // if set to 1, then tries to execute cuda code which fails due to linking problems +#define GEANT4_ENABLE_CUDA 0 +#if GEANT4_ENABLE_CUDA + #include "CUDA_G4NeutronHPVector.h" +#endif // if the ranges do not match, constant extrapolation is used. G4NeutronHPVector & operator + (G4NeutronHPVector & left, G4NeutronHPVector & right) { + G4cout << "G4NeutronHPVector plus operator" << G4endl; G4NeutronHPVector * result = new G4NeutronHPVector; G4int j=0; G4double x; @@ -85,6 +87,53 @@ G4NeutronHPVector::G4NeutronHPVector() { G4cout << "G4NeutronHPVector Constructed (no params)" << G4endl; + + + #define arraySize 15 + int *arr1 = new int[arraySize]; + int *arr2 = new int[arraySize]; + for (int i = 0; i < arraySize; i++) { + arr1[i] = (int)rand() % 100; + arr2[i] = (int)rand() % 100; + } + int *sum = new int[arraySize]; + + #if GEANT4_ENABLE_CUDA + G4cout << "\n***************************** CUDA ***********************************" << G4endl; + std::clock_t start = std::clock(); + CUDA_sumArrays(arr1, arr2, sum, arraySize); + std::clock_t end = std::clock(); + + G4cout << "Sum of ["; + for (int i = 0; i < arraySize; i++) { + if (i == arraySize-1) + G4cout << arr1[i] << "]"; + else + G4cout << arr1[i] << ", "; + } + G4cout << "\nand of ["; + for (int i = 0; i < arraySize; i++) { + if (i == arraySize-1) + G4cout << arr2[i] << "]"; + else + G4cout << arr2[i] << ", "; + } + G4cout << "\n Array ["; + for (int i = 0; i < arraySize; i++) { + if (i == arraySize-1) + G4cout << sum[i] << "]"; + else + G4cout << sum[i] << ", "; + } + G4cout << "\nComputation done in " << double(end-start)/CLOCKS_PER_SEC << " s" << G4endl; + G4cout << "******************************** CUDA ********************************\n" << G4endl; + #else + G4cout << "CUDA is disabled -- G4NeutronHPVector::G4NeutronHPVector()" << G4endl; + #endif + + + + theData = new G4NeutronHPDataPoint[20]; nPoints=20; nEntries=0; @@ -116,6 +165,7 @@ G4NeutronHPVector::~G4NeutronHPVector() { + G4cout << "G4NeutronHPVector destroyed" << G4endl; // if(Verbose==1)G4cout <<"G4NeutronHPVector::~G4NeutronHPVector"<nEntries) throw G4HadronicException(__FILE__, __LINE__, "Skipped some index numbers in G4NeutronHPVector"); if(i==nPoints) { @@ -231,6 +285,7 @@ Merge(G4InterpolationScheme aScheme, G4double aValue, G4NeutronHPVector * active, G4NeutronHPVector * passive) { + G4cout << "G4NeutronHPVector Merge" << G4endl; // interpolate between labels according to aScheme, cut at aValue, // continue in unknown areas by substraction of the last difference. @@ -293,7 +348,7 @@ void G4NeutronHPVector::ThinOut(G4double precision) { - +G4cout << "G4NeutronHPVector THINOUT" << G4endl; //#if CUDA_ENABLED // float result = squareArray(100); // G4cout <<"G4NeutronHPVector::ThinOut test on GPU result: "<< result << G4endl; @@ -345,6 +400,7 @@ G4bool G4NeutronHPVector::IsBlocked(G4double aX) { + G4cout << "G4NeutronHPVector isBlocked" << G4endl; G4bool result = false; std::vector::iterator i; for(i=theBlocked.begin(); i!=theBlocked.end(); i++) @@ -362,6 +418,7 @@ G4double G4NeutronHPVector::Sample() // Samples X according to distribution Y { + G4cout << "G4NeutronHPVector Sample" << G4endl; G4double result; G4int j; for(j=0; j-DBL_MAX/2.) return the15percentBorderCash; G4double result; if(GetVectorLength()==1) @@ -483,6 +541,7 @@ G4double G4NeutronHPVector::Get50percentBorder() { + G4cout << "G4NeutronHPVector Get50percentBorder" << G4endl; if(the50percentBorderCash>-DBL_MAX/2.) return the50percentBorderCash; G4double result; if(GetVectorLength()==1)