Could I use openmp with rootcling?


_ROOT Version: homebrew 6.20.04
_Platform:mac os x


   #include <omp.h>
   #include <iostream>
   //#include <ROOT/RDF/RInterface.hxx>
   #include <TSystem.h>
   using namespace std;
   void test()
   {
   //  ROOT::EnableImplicitMT();
     gSystem->AddLinkedLibs("-lgomp");
     gSystem->AddLinkedLibs("-lomp");
   #pragma omp parallel for
     for(int i = 0; i<10; i++)
     {
       cout<<i;
     }
     cout<<endl;
   }

output

0123456789

openmp not working

but if I use cling, it’s OK below

cling -I/usr/local/include -fopenmp -llibomp test.cpp

how could I use openmp with rootcling?

Hi,

I guess you don’t mean rootcling, the dictionary generator:
https://root.cern.ch/interacting-shared-libraries-rootcling

You mean how you can run that code with ROOT’s interpreter? Can you convert it in a macro and run it as explained here?

https://root.cern.ch/working-macros

I guess you need to also set the path in which the library is:

gSystem->AddLinkedLibs("-L/my/path -lanylib");

yes, my mistake, what I meant is that
could I use openmp at root interpreter

openmp not working with result 0123456789
It seem it use only one core. not parallel

I don’t see why it should not create your threads, what happens if you compile the same program instead of running it via the ROOT interpreter?

If I compile it, it’s OK for parallel

@Axel any idea why the openmp code is serialized when executed via the interpreter, as opposed to compiled?