Skip to content

Commit 25c059b

Browse files
committed
Merge pull request #2 from AAAlvesJr/master
Merge to first patch version
2 parents 113cd59 + ab61644 commit 25c059b

File tree

6 files changed

+292
-30
lines changed

6 files changed

+292
-30
lines changed

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ option(BUILD_DOCUMENTATION "Create and install the HTML based API documentation
5050
#options to gcc
5151
include(CheckCXXCompilerFlag)
5252
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
53-
if(COMPILER_SUPPORTS_CXX11)
54-
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
53+
if(NOT COMPILER_SUPPORTS_CXX11)
54+
message(FATAL "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
5555
endif()
5656

5757
#options to gcc
@@ -72,15 +72,17 @@ if(CUDA_FOUND)
7272
# Detect CUDA architecture and get best NVCC flags
7373

7474
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindCudaArch.cmake)
75+
7576
SELECT_NVCC_ARCH_FLAGS(NVCC_FLAGS_EXTRA)
77+
7678
LIST(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA})
7779
#hack for gcc 5.x.x
7880
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
7981
LIST(APPEND CUDA_NVCC_FLAGS " -D_MWAITXINTRIN_H_INCLUDED ")
8082
endif()
8183
endif(CUDA_FOUND)
8284

83-
if((CUDA_FOUND) AND (CUDA_GPU_DETECT_OUTPUT))
85+
if( CUDA_FOUND )
8486

8587
SET(BUILD_CUDA_TARGETS ON)
8688

mcbooster/Generate.h

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <mcbooster/functors/DecayMothers.h>
5050
#include <mcbooster/functors/RandGen.h>
5151
#include <mcbooster/functors/FlagAcceptReject.h>
52+
#include <mcbooster/functors/IsAccepted.h>
5253
#include <mcbooster/strided_iterator.h>
5354

5455
#include <thrust/copy.h>
@@ -169,9 +170,10 @@ class PhaseSpace {
169170
* - _NEvents: it is the number of events to be generated.
170171
*/
171172
PhaseSpace(GReal_t _MotherMass, vector<GReal_t> _Masses, GLong_t _NEvents) :
172-
fNDaughters(_Masses.size()), fNEvents(_NEvents), fRandNumbers(
173-
(3 * _Masses.size() - 2) * _NEvents, 0.0), fMaxWeight(0.0), RND_Time(
174-
0.0), EVT_Time(0.0), EXP_Time(0.0) {
173+
fNDaughters(_Masses.size()), fNEvents(_NEvents),
174+
fRandNumbers((3 * _Masses.size() - 2) * _NEvents, 0.0), fMaxWeight(0.0),
175+
RND_Time(0.0), EVT_Time(0.0), EXP_Time(0.0), fNAccepted(0)
176+
{
175177

176178
if (_Masses.size() < 2 || _Masses.size() > 9) {
177179
cout
@@ -252,6 +254,10 @@ class PhaseSpace {
252254
return fNEvents;
253255
}
254256

257+
inline GLong_t GetNAccepted() const {
258+
return fNAccepted;
259+
}
260+
255261
/**
256262
* Returns a device vector with the event weights.
257263
*/
@@ -292,7 +298,7 @@ class PhaseSpace {
292298
* Export the events and all related information to host.
293299
*/
294300
void Export(Events *_Events);
295-
301+
void ExportUnweighted(Events *_Events);
296302
/**
297303
* Flag the accepted and rejected events
298304
*/
@@ -328,6 +334,7 @@ class PhaseSpace {
328334

329335
GLong_t fNEvents; ///< Number of events.
330336
GInt_t fNDaughters;///< Number of daughters.
337+
GLong_t fNAccepted;
331338
GReal_t RND_Time;///< Random number generation time interval seconds.
332339
GReal_t EVT_Time;///< Event generation time interval in seconds.
333340
GReal_t EXP_Time;///< Events export time interval in seconds.
@@ -339,6 +346,7 @@ class PhaseSpace {
339346
Particles_d fDaughters[kMAXP];///< Array of device vectors with the daughter four-vectors
340347
RealVector_d fRandNumbers;///<
341348

349+
342350
};
343351

344352
GULong_t PhaseSpace::Unweight()
@@ -365,11 +373,90 @@ GULong_t PhaseSpace::Unweight()
365373
kTrue);
366374

367375
}
376+
fNAccepted=count;
368377
return count;
369378

370379
}
371380

372381

382+
383+
void PhaseSpace::ExportUnweighted(Events *_Events) {
384+
/**
385+
* Export the events and all related information to an Events object properly initialized.
386+
*/
387+
388+
if(!fNAccepted) Unweight();
389+
390+
391+
_Events->fMaxWeight = fMaxWeight;
392+
393+
#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_BACKEND_OMP || THRUST_DEVICE_SYSTEM==THRUST_DEVICE_BACKEND_TBB
394+
395+
#pragma omp parallel num_threads( fNDaughters + 1 )
396+
{
397+
398+
if (omp_get_thread_num() < fNDaughters )
399+
{
400+
thrust::copy_if( fDaughters[omp_get_thread_num()].begin(),fDaughters[omp_get_thread_num()].end(),
401+
fAccRejFlags.begin(),
402+
_Events->fDaughters[omp_get_thread_num()].begin(), isAccepted() );
403+
}
404+
405+
if (omp_get_thread_num() == fNDaughters )
406+
{
407+
thrust::copy_if(fWeights.begin(), fWeights.end(),
408+
fAccRejFlags.begin(),
409+
_Events->fWeights.begin(), isAccepted() );
410+
411+
thrust::copy_if(fAccRejFlags.begin(), fAccRejFlags.end(),
412+
fAccRejFlags.begin(),
413+
_Events->fAccRejFlags.begin(), isAccepted() );
414+
415+
}
416+
417+
}
418+
419+
#else
420+
421+
cudaStream_t s[fNDaughters + 1];
422+
423+
for (GInt_t d = 0; d <= fNDaughters; d++) {
424+
425+
CUDA_CHECK_RETURN(
426+
cudaStreamCreateWithFlags(&s[d], cudaStreamNonBlocking));
427+
}
428+
429+
430+
431+
thrust::copy_if( thrust::cuda::par.on(s[fNDaughters]),
432+
fWeights.begin(), fWeights.end(),
433+
fAccRejFlags.begin(),
434+
_Events->fWeights.begin(), isAccepted() );
435+
436+
437+
thrust::copy_if( thrust::cuda::par.on(s[fNDaughters]),
438+
fAccRejFlags.begin(), fAccRejFlags.end(),
439+
fAccRejFlags.begin(),
440+
_Events->fAccRejFlags.begin(), isAccepted() );
441+
442+
443+
for (GInt_t d = 0; d < fNDaughters; d++) {
444+
445+
thrust::copy_if( thrust::cuda::par.on(s[d]),
446+
fDaughters[d].begin(),fDaughters[d].end(),
447+
fAccRejFlags.begin(),
448+
_Events->fDaughters[d].begin(), isAccepted() );
449+
450+
}
451+
452+
cudaDeviceSynchronize();
453+
for (GInt_t d = 0; d <= fNDaughters; d++)
454+
cudaStreamDestroy(s[d]);
455+
456+
#endif
457+
458+
}
459+
373460
void PhaseSpace::Export(Events *_Events) {
374461
/**
375462
* Export the events and all related information to an Events object properly initialized.

mcbooster/MCBooster.h

Lines changed: 110 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,159 @@
44
#define MCBooster_VERSION_PATCH 0
55
/**
66
\mainpage
7-
87
MCBooster
98
=========
109
1110
What is it?
1211
-----------
12+
1313
MCBooster is an header only library designed for the fast generation of
14-
phase space events. The library make use of thrust library and can deploy OpenMP
15-
threads, CUDA and Xeon Phi cores. It is focused on performance and precision.
14+
phase space events. The library makes use of Thrust and can deploy OpenMP
15+
threads, CUDA and Xeon Phi cores. It is focused on performance and precision.
16+
17+
The libray core algorithm follow as close as it is possible the implementation of the class [TGenPhaseSpace](https://root.cern.ch/doc/master/TGenPhaseSpace_8cxx.html)
18+
from [ROOT framwork](https://root.cern.ch/),
19+
which is based on the [GENBOD function (W515 from CERNLIB)](http://cernlib.web.cern.ch/cernlib/mc/genbod.html)
20+
using the Raubold and Lynch method as described in
21+
22+
[_F. James, Monte Carlo Phase Space, CERN 68-15 (1968)_](https://cds.cern.ch/record/275743/files/CERN-68-15.pdf).
23+
24+
Main features
25+
-------------
26+
27+
Generates phase space Monte Carlo samples with up to nine particles in the final state, using very simple
28+
and intuitive interface. Example:
29+
```c++
30+
//generating 10M events of B0 -> J/psi K pi
31+
#include <mcbooster/GTypes.h>
32+
#include <mcbooster/Vector4R.h>
33+
#include <mcbooster/Generate.h>
34+
...
35+
//setting the mother particle
36+
Vector4R B0(5.2795, 0.0, 0.0, 0.0);
37+
38+
//setting the masses of the daughter particles
39+
vector<GReal_t> masses;
40+
masses.push_back(3.096916); // J/psi
41+
masses.push_back(0.493677); // K
42+
masses.push_back(0.13957018); // pi
43+
44+
//generator ctor for 10M events
45+
PhaseSpace phsp(B0.mass(), massesB0, 10000000);
46+
47+
//run the generator
48+
phsp.Generate(B0);
49+
50+
//Unweight the events flags the accepted and rejected events
51+
phsp.Unweight();
52+
53+
//export events to the host (in case it is necessary)
54+
Events *GenEvents = new Events(masses.size(), 10000000);
55+
phsp.Export(GenEvents);
56+
...
57+
```
58+
Other key features are:
59+
60+
1. Decays can be generated with mother particles are rest or with a definite four-vector.
61+
this feature allows the generation of sequential decays.
62+
63+
2. Generates weighted and "unweighted" samples simultaneously.
64+
65+
3. Allows the fast parallel evaluation of arbitrary functions taking as
66+
argument up to ten particles as input.
67+
68+
4. Allows the fast parallel evaluation of arrays of variables simultaneously.
69+
70+
MCBooster also provides a bunch of custom types, containers and an increasing number of algorithms
71+
to maximaze performance, avoid unecessary usage of memory and grant flexibility and protability between
72+
host and device calculations and deployment scenarios.
73+
74+
Just changing .cu to .cpp in any source code writen only using the provided cosntructs is enough
75+
to compile your application for OpenMP using GCC in a machine without a NVIDIA GPU installed.
76+
77+
Many other possibilities and functionaties, bounded only by the creativity of the users.
1678
1779
The Latest Version
1880
------------------
1981
20-
The latest version can be found on the
82+
The latest version can be found on the
2183
[project relases page](https://github.com/MultithreadCorner/MCBooster/releases).
2284
2385
Documentation
2486
-------------
2587
2688
The complete and updated [Doxygen](http://www.doxygen.org/) source code documentation of this release is available in HTML format on the
2789
[reference manual](http://multithreadcorner.github.io/MCBooster/) webpage.
28-
User can also browse the documentation by class, file or name using the following links:
90+
Users can also browse the documentation by class, file or name using the following links:
2991
30-
1.[classe](http://multithreadcorner.github.io/MCBooster/classes.html)
92+
1.[classes](http://multithreadcorner.github.io/MCBooster/classes.html)
3193
32-
2.[file](http://multithreadcorner.github.io/MCBooster/files.html)
94+
2.[files](http://multithreadcorner.github.io/MCBooster/files.html)
3395
34-
3.[name](http://multithreadcorner.github.io/MCBooster/namespacemembers.html)
96+
3.[names](http://multithreadcorner.github.io/MCBooster/namespacemembers.html)
3597
98+
Installation and requirements
99+
-----------------------------
100+
101+
MCBooster is a header only library, so no build process is necessary to install it.
102+
Just place the `mcbooter` folder and its contents where your system can find it.
103+
The library run on Linux systems and requires C++11 and the [Thrust library](https://thrust.github.io/).
104+
Some examples demonstrating the basic features of the library are included in the `src` folder.
105+
These code samples require [ROOT](https://root.cern.ch/) and [TCLAP](http://tclap.sourceforge.net/) library.
106+
CUDA based projects will require a local installation of [CUDA Tookit](https://developer.nvidia.com/cuda-toolkit) with version 6.5 or higher.
107+
Alternatively, projects the targeting [OpenMP](http://openmp.org/wp/) backend can be compiled with either nvcc or gcc.
108+
The CUDA runtime is not required to use OpemMP with gcc.
36109
37110
Examples
38111
--------
39112
40-
Some example code samples demonstrating the basic usage of the library are stored in the src directory.
113+
Some example code samples demonstrating the basic usage of the library are stored in the src directory, in the project source tree.
41114
These samples can be built using [CMAKE](https://cmake.org/) according the following instructions:
42115
43116
1. clone the git repository: `git clone https://github.com/MultithreadCorner/MCBooster.git`
44117
2. go to MCBooster directory: `cd MCBooster`
45-
3. create a build directory: `mkdir build`
118+
3. create a build directory: `mkdir build`
119+
4. go to build directory: `cd build`
46120
4. `cmake ../`
47121
5. `make`
48122
49-
The targets will be installed into directory-of-the-project/bin. To run an example do ./example-name
123+
Users with root privilegies can do `make install` and get the targets installed into system-install-dir/bin
124+
(usually /usr/local. __Notice the project installation path is printed out in the setp 4__). Users without root privileges can point the installation path to a different location cmake `-DCMAKE_INSTALL_PREFIX=<user-path>/ ../`.
50125
51-
Installation and requirements
52-
-----------------------------
126+
The examples are named according to the convention `MCBooster_Example_<BACKEND AND COMPILER>_<EXAMPLE NAME>`. To run an example do `./example-name`.
127+
The examples are described below:
53128
54-
MCBooster is a header only library, so no build process is necessary to install it.
55-
The library run on Linux systems and requires C++11 and the [Thrust library](https://thrust.github.io/). The code samples require [ROOT](https://root.cern.ch/) and [TCLAP](http://tclap.sourceforge.net/) library.
56-
CUDA based projects will require a local installation of [CUDA Tookit](https://developer.nvidia.com/cuda-toolkit) with version 6.5 or higher.
57-
Alternatively, projects the targeting [OpenMP](http://openmp.org/wp/) backend can be compiled with nvcc or gcc directly.
129+
1. __B2KPiJpsi__ : Generates a sample of B0 -> Jpsi K pi, with J/psi -> mu+ mu- and calculates in parallel, for each event, the variables:
130+
* M(K,pi), the Kpi invariant mass.
131+
* M(J/psi,pi), the J/psipi invariant mass.
132+
* cos theta(K), the helicity angle of the Kpi.
133+
* cos theta(mu), the helicity angle of the J/psi
134+
* phi, the angle between the decay planes
135+
136+
The program print some events and timing information to sdtout and plotsthe distributions of the above variables plus the B0 -> J/psiK pi Dalitz plot.
137+
138+
2. __GenerateSample__ : Takes arguments from the command line, generates a sample and save it into a ROOT TTree.
139+
140+
3. __PerformanceTest__: Meausure the time to generate and export samples in function of the number of events and number of particles.
58141
59142
Licensing
60143
---------
61144
62145
MCBooster is released under the [GNU General Public License version 3](http://www.gnu.org/licenses/gpl-3.0.en.html). Please see the file called [COPYING](https://github.com/MultithreadCorner/MCBooster/blob/master/COPYING).
63146
147+
Contact the developers
148+
----------------------
149+
Here’s what you should do if you need help or would like to contribute:
150+
151+
1. If you need help or would like to ask a general question, subscribe and use https://groups.google.com/d/forum/mcbooster.
152+
2. If you found a bug, use GitHub issues.
153+
3. If you have an idea, use GitHub issues.
154+
4. If you want to contribute, submit a pull request.
155+
64156
Author
65157
--------
66158
67-
MCBooster is developed and mantained by [Antonio Augusto Alves Jr](@AAAlvesJr).
159+
MCBooster was created and is mantained by [Antonio Augusto Alves Jr](@AAAlvesJr).
68160
69161
Acknowledgement
70162
---------------

0 commit comments

Comments
 (0)