OpenMP

Hi,

I want to use OpenMP with root to speed up my script. I have mannaged to install OpenMP and it works fine, but I have no idea how to use it with root. Before posting I have looked at previous replies root.cern.ch/root/roottalk/roottalk10/1122.html , but it didn’t worked for me.

The error message I get:

fatal error: 'omp.h' file not found #include <omp.h>
The root version is 6.04/16 and with mac OS X 10.10.5.
Hope someone can help.

Hi,

there are several ways to express parallelism with ROOT: e.g. multithreading with threads managed by the user, Task based parallelism, multiprocessing. My suggestion is to go and have a look to the Multicore Tutorials: root.cern.ch/doc/master/group__ … icore.html

If you want to stick to openmp, what are the steps you are taking to compile your program and what program are you compiling? Note that the resource protection applied in the multithreaded case (see e.g. root.cern.ch/doc/master/mt001__ … os_8C.html will have to be in place).

Cheers,
D

Thanks for the reply.

I load my libraries with gROOT->LoadMacro():

void Load()
{
    gROOT->LoadMacro("Vector.cc+g");
    gROOT->LoadMacro("Particle.cc+g");
    gROOT->LoadMacro("Detector.cc+g");
}

And to start my code I simply write in the terminal : root -l Load.C

My code could look like:

TFile *f = TFile::Open("Hijing_000244918_AA_05020_30k.root" ,"READ");
TTree *t = static_cast<TTree*>(f->Get("T"));
Header*       h = new Header;
TClonesArray* p = new TClonesArray("TParticle");
t->SetBranchAddress("header",    &(h->run));
t->SetBranchAddress("particles", &p);

    for (int i = 0; i < t->GetEntries(); i++) { /// Loop over each event
        vector<Vector> particles_intersection_mcp;
        t->GetEntry(i);
           for (int j = 0;   j < p->GetEntries(); j++) { Loop over particles
                TParticle* q = static_cast<TParticle*>(p->At(j));
                TParticlePDG* pdg = pdgDb->GetParticle(q->GetPdgCode());
                    for (unsigned int i = 0; i < position_array_quartz_T0A.size(); i++){ Intersection with each detector
            			“ Findes intersection with some detector class and the intersection vectors are analyzed with root histogram functions"
                    }
                } 
            }

I want to speed ud the loop where the intersection with the detector class is analyzed by using OpenMP.
To make it clear it’s only the detector class function, that should run faster, and the plotting with the ROOT functions is not the problem.

Hi,

openmp is not supported yet in interpreted macros, it will be in the future.
I therefore see two options: either exploiting the aforementioned ways ROOT provides to express parallelism (all described in detail here root.cern.ch/doc/master/group__ … icore.html) or compiling your code with a compiler supporting openmp, e.g. gcc.

Danilo

Hi Danilo,

I have installed gcc 5.3.0 and I can run a C++ code by : g+±5.0 main.cpp -fopenmp -o program.
But I am not sure how to compile it with my own code using ROOT libraries.

Hi,

that is the simplest part :slight_smile:

g++ -o myProgram myProgram.cpp `root-config --cflags --libs`

will do the job.

Cheers,
Danilo

That sounds easy :slight_smile:

My libraries looks like:

void Load()
{
    gROOT->LoadMacro("Vector.cc+g");
    gROOT->LoadMacro("Particle.cc+g");
    gROOT->LoadMacro("Detector.cc+g");
    gROOT->LoadMacro("mcp.cc+g");
    gROOT->LoadMacro("McpFunctions.cc+g");
    gROOT->LoadMacro("Read_data.cc+g");
    gROOT->LoadMacro("eventFunction.cc+g");
    gROOT->Macro("ep.cpp+g");    
}

I think in my case I would start it:

g++ -o myprogram ep.cpp `root-config --cflags --libs`

Since ep.cpp is the main program, but I still get the following error:

ep.cpp:11:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^
1 error generated.

Do you actually have openmp available on your machine?

D

Another thing: the libraries you are building with Aclic will need to be built with a compiler invocation as shared objects and linked with your executable, but one step at the time.

Sorry for bothering you, but I am not that good at programming, could you give me a hint how to implement it?

Hi,

for the openmp installation, I think all sorts of instructions on the web can be found, depending on your platform.
For what concerns the compilation of libraries, this is a very general and standard procedure:

g++ -o libVector.so Vector.cc -fPIC -shared `root-config --libs --cflags` -g
g++ -o myProgram myProgram.cpp -l Vector -L path/to/where/libVector/is/ `root-config --libs --cflags` -g

D

Thank you :slight_smile: