Re: OpenMP + ACLiC

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Wed, 15 Sep 2010 18:19:32 -0500

> #pragma omp parallel private(top, bottom)

Humm .. this is going to be a problem :(. The dictionary generated by rootcint (via ACliC) wrap your code and #defines private to have the value public.

You can try to add before #include <omp.h>

#ifdef private
#undef private
#endif

Cheers,
Philippe.

On 9/15/10 5:18 PM, OKUMURA, Akira wrote:
> Hello Philippe,
>
> The followings are my codes and steps. I confirmed that the standalone version was compiled with OpenMP by outputting "Hello, OpenMP!" twice (I'm using dual core).
>
> === pi.C ===
> #include <omp.h>
> #include <time.h>
> #include <iostream>
>
> void pi()
> {
> const int kN = 100000000;
> long double top = 0.L;
> long double bottom = 0.L;
> long double kStep = 1.L/kN;
> long double sum = 0.L;
>
> #ifndef __CINT__
> #pragma omp parallel
> std::cout << "Hello, OpenMP!\n";
> #endif
>
> #ifndef __CINT__
> #pragma omp parallel private(top, bottom)
> #endif
> {
> #ifndef __CINT__
> #pragma omp for reduction(+:sum)
> #endif
> for(int i = 0; i < kN; i++) {
> top = 4.L/(1.L + (kStep*i)*(kStep*i));
> bottom = 4.L/(1.L + (kStep*(i+1))*(kStep*(i + 1)));
> sum += (top + bottom)*kStep/2.L;
> } // i
> }
> std::cout.precision(16);
> std::cout << "pi = " << sum << "\n";
> }
> ==========
>
> === ACLiC steps ===
> $ root -n
> root [0] TString cmd(gSystem->GetMakeSharedLib())
> root [1] cmd.ReplaceAll("g++", "g++ -fopenmp")
> (class TString)"cd $BuildDir ; g++ -fopenmp -c $Opt -m64 -pipe -Wshadow -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -D_REENTRANT -pthread $IncludePath $SourceFiles ; MACOSX_DEPLOYMENT_TARGET=10.6 g++ -fopenmp $ObjectFiles -dynamiclib -single_module -undefined dynamic_lookup -lwcs $DepLibs -o $SharedLib"
> root [2] gSystem->SetMakeSharedLib(cmd)
> root [3] .L pi.C++
> Info in <TUnixSystem::ACLiC>: creating shared library /Users/oxon/./pi_C.so
> In file included from /Users/oxon/pi_C_ACLiC_dict.h:34,
> from /Users/oxon/pi_C_ACLiC_dict.cxx:16:
> /Users/oxon/./pi.C: In function ‘void pi()’:
> /Users/oxon/./pi.C:19: error: expected ‘#pragma omp’ clause before ‘public’
> i686-apple-darwin10-g++-4.2.1: /Users/oxon/pi_C_ACLiC_dict.o: No such file or directory
> Error in <ACLiC>: Compilation failed!
> ====================
>
> === main.cxx ===
> #include "pi.C"
>
> int main()
> {
> pi();
>
> return 0;
> }
> ==============
>
> === stand alone (used the same options as ACLiC) ===
> $ g++ -fopenmp main.cxx -m64 -pipe -Wshadow -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -D_REENTRANT -pthread
> $ ./a.out
> Hello, OpenMP!
> Hello, OpenMP!
> pi = 3.141592653589793
>
> $ /usr/bin/i686-apple-darwin10-g++-4.2.1 -fopenmp main.cxx -m64 -pipe -Wshadow -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -D_REENTRANT -pthread
> $ ./a.out
> Hello, OpenMP!
> Hello, OpenMP!
> pi = 3.141592653589793
> ==================
>
> Regards,
>
> --
> OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
> Institute of Space and Astronautical Science (ISAS/JAXA)
> Now at KIPAC/SLAC/Stanford
> Varian Physics #306
> 382 Via Pueblo Mall, MC 406 Stanford, CA94305
> TEL 650-736-0971/FAX 650-724-5065
> Skype : okumura.akira
>
> On 2010/09/15, at 12:50, Philippe Canal wrote:
>
>> Hi Akira,
>>
>> What are all the steps you take to compile the standalone case?
>>
>> Cheers,
>> Philippe.
>>
>> On 9/15/10 1:25 PM, OKUMURA, Akira wrote:
>>> Hello Philippe,
>>>
>>> Thank you again. But I get the same error again. Does this work on your machine? I tried gcc 4.2.1 on Snow Leopard and gcc 4.4.0 on Scientific Linux 5.
>>>
>>> $ root
>>> root [0] TString cmd(gSystem->GetMakeSharedLib())
>>> root [1] cmd.ReplaceAll("g++", "g++ -fopenmp")
>>> (class TString)"cd $BuildDir ; g++ -fopenmp -c $Opt -m64 -pipe -Wshadow -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -D_REENTRANT -pthread $IncludePath $SourceFiles ; MACOSX_DEPLOYMENT_TARGET=10.6 g++ -fopenmp $ObjectFiles -dynamiclib -single_module -undefined dynamic_lookup -lwcs $DepLibs -o $SharedLib"
>>> root [2] gSystem->SetMakeSharedLib(cmd)
>>> root [3] .L pi.C++
>>> Info in <TUnixSystem::ACLiC>: creating shared library /Users/oxon/./pi_C.so
>>> In file included from /Users/oxon/pi_C_ACLiC_dict.h:34,
>>> from /Users/oxon/pi_C_ACLiC_dict.cxx:16:
>>> /Users/oxon/./pi.C: In function ‘void pi()’:
>>> /Users/oxon/./pi.C:14: error: expected ‘#pragma omp’ clause before ‘public’
>>> i686-apple-darwin10-g++-4.2.1: /Users/oxon/pi_C_ACLiC_dict.o: No such file or directory
>>> Error in <ACLiC>: Compilation failed!
>>>
>>> Regards,
>>>
>>> --
>>> OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
>>> Institute of Space and Astronautical Science (ISAS/JAXA)
>>> Now at KIPAC/SLAC/Stanford
>>> Varian Physics #306
>>> 382 Via Pueblo Mall, MC 406 Stanford, CA94305
>>> TEL 650-736-0971/FAX 650-724-5065
>>> Skype : okumura.akira
>>>
>>> On 2010/09/15, at 10:30, Philippe Canal wrote:
>>>
>>>> Hi Akira,
>>>>
>>>> You also need to add *-fopenmp to the compiler invocations.
>>>> For that do:
>>>> TString cmd( gSystem->GetMakeSharedLibs );
>>>> cmd.ReplaceAll("g++","g++ -fopenmp");
>>>> gSystem->SetMakeSharedLibs(cmd);
>>>>
>>>> Cheers,
>>>> Philippe.
>>>> *
>>>> On 9/15/10 11:25 AM, OKUMURA, Akira wrote:
>>>>> Hello Philippe,
>>>>>
>>>>> Thanks for the advise. But I still get the same error.
>>>>>
>>>>> #include <omp.h>
>>>>> #include <time.h>
>>>>> #include <iostream>
>>>>>
>>>>> void pi()
>>>>> {
>>>>> const Int_t kN = 100000000;
>>>>> long double top = 0.L;
>>>>> long double bottom = 0.L;
>>>>> long double kStep = 1.L/kN;
>>>>> long double sum = 0.L;
>>>>>
>>>>> #ifndef __CINT__
>>>>> #pragma omp parallel private(top, bottom)
>>>>> #endif
>>>>> {
>>>>> #ifndef __CINT__
>>>>> #pragma omp for reduction(+:sum)
>>>>> #endif
>>>>> for(Int_t i = 0; i < kN; i++) {
>>>>> top = 4.L/(1.L + (kStep*i)*(kStep*i));
>>>>> bottom = 4.L/(1.L + (kStep*(i+1))*(kStep*(i + 1)));
>>>>> sum += (top + bottom)*kStep/2.L;
>>>>> } // i
>>>>> }
>>>>> std::cout.precision(16);
>>>>> std::cout << "pi = " << sum << "\n";
>>>>> }
>>>>>
>>>>> root [4] .L pi.C++
>>>>> Info in <TUnixSystem::ACLiC>: creating shared library /Users/oxon/./pi_C.so
>>>>> In file included from /Users/oxon/pi_C_ACLiC_dict.h:34,
>>>>> from /Users/oxon/pi_C_ACLiC_dict.cxx:16:
>>>>> /Users/oxon/./pi.C: In function ‘void pi()’:
>>>>> /Users/oxon/./pi.C:14: error: expected ‘#pragma omp’ clause before ‘public’
>>>>> i686-apple-darwin10-g++-4.2.1: /Users/oxon/pi_C_ACLiC_dict.o: No such file or directory
>>>>> Error in <ACLiC>: Compilation failed!
>>>>>
>>>>> Regards,
>>>>>
>>>>> --
>>>>> OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
>>>>> Institute of Space and Astronautical Science (ISAS/JAXA)
>>>>> Now at KIPAC/SLAC/Stanford
>>>>> Varian Physics #306
>>>>> 382 Via Pueblo Mall, MC 406 Stanford, CA94305
>>>>> TEL 650-736-0971/FAX 650-724-5065
>>>>> Skype : okumura.akira
>>>>>
>>>>> On 2010/09/15, at 8:53, Philippe Canal wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> You need to at least hide the #pragma from CINT:
>>>>>>
>>>>>> #ifndef __CINT__
>>>>>> #pragma omp parallel private(top, bottom)
>>>>>> #endif
>>>>>> {
>>>>>> #ifndef __CINT__
>>>>>> #pragma omp for reduction(+:sum)
>>>>>> #endif
>>>>>> for(Int_t i = 0; i < kN; i++) {
>>>>>>
>>>>>> Cheers,
>>>>>> Philippe.
>>>>>>
>>>>>> On 9/15/10 10:47 AM, OKUMURA, Akira wrote:
>>>>>>> Hello ROOTers,
>>>>>>>
>>>>>>> Does ACLiC support OpenMP?
>>>>>>>
>>>>>>> I started learning OpenMP to improve the speed of my analysis. The following is an example to calculate pi with OpenMP.
>>>>>>>
>>>>>>> === pi.C ===
>>>>>>> #include <omp.h>
>>>>>>> #include <time.h>
>>>>>>> #include <iostream>
>>>>>>>
>>>>>>> void pi()
>>>>>>> {
>>>>>>> const Int_t kN = 100000000;
>>>>>>> long double top = 0.L;
>>>>>>> long double bottom = 0.L;
>>>>>>> long double kStep = 1.L/kN;
>>>>>>> long double sum = 0.L;
>>>>>>>
>>>>>>> #pragma omp parallel private(top, bottom)
>>>>>>> {
>>>>>>> #pragma omp for reduction(+:sum)
>>>>>>> for(Int_t i = 0; i < kN; i++) {
>>>>>>> top = 4.L/(1.L + (kStep*i)*(kStep*i));
>>>>>>> bottom = 4.L/(1.L + (kStep*(i+1))*(kStep*(i + 1)));
>>>>>>> sum += (top + bottom)*kStep/2.L;
>>>>>>> } // i
>>>>>>> }
>>>>>>> std::cout.precision(16);
>>>>>>> std::cout << "pi = " << sum << "\n";
>>>>>>> }
>>>>>>> ============
>>>>>>>
>>>>>>> But I got the following error.
>>>>>>> ============
>>>>>>> root [0] gSystem->SetIncludePath("-fopenmp")
>>>>>>> root [1] gSystem->AddLinkedLibs("-lgomp")
>>>>>>> root [2] .L pi.C+O
>>>>>>> Info in <TUnixSystem::ACLiC>: creating shared library /Users/oxon/./pi_C.so
>>>>>>> In file included from /Users/oxon/pi_C_ACLiC_dict.h:34,
>>>>>>> from /Users/oxon/pi_C_ACLiC_dict.cxx:16:
>>>>>>> /Users/oxon/./pi.C: In function ‘void pi()’:
>>>>>>> /Users/oxon/./pi.C:13: error: expected ‘#pragma omp’ clause before ‘public’
>>>>>>> i686-apple-darwin10-g++-4.2.1: /Users/oxon/pi_C_ACLiC_dict.o: No such file or directory
>>>>>>> Error in <ACLiC>: Compilation failed!
>>>>>>> ============
>>>>>>>
>>>>>>> It seems that some of OpenMP words are not handled properly in generation of a dictionary. I suppose ACLiC does not support OpenMP yet.
>>>>>>>
>>>>>>> If ACLiC supports OpenMP, how can I run the script in ROOT? This example runs as I expected in standalone C++ program.
>>>>>>>
>>>>>>> I am using ROOT trunk and GCC (i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)) on Snow Leopard.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> --
>>>>>>> OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
>>>>>>> Institute of Space and Astronautical Science (ISAS/JAXA)
>>>>>>> Now at KIPAC/SLAC/Stanford
>>>>>>> Varian Physics #306
>>>>>>> 382 Via Pueblo Mall, MC 406 Stanford, CA94305
>>>>>>> TEL 650-736-0971/FAX 650-724-5065
>>>>>>> Skype : okumura.akira
>>>>>>>
Received on Thu Sep 16 2010 - 01:19:41 CEST

This archive was generated by hypermail 2.2.0 : Thu Sep 16 2010 - 05:50:01 CEST