Doing "install pythia8" how do I tell the compiler that it needs to use a "-std=c++11" flag?

Asked by Henry

I have downloaded the latest version of madgraph (to check if that will solve another issue) and I am trying to install pythia with the madgraph prompt. The installer runs into an error "Range-based 'for' loops are not allowed in C++98 mode". In theory this can be resolved by compiling with "-std=c++11".

I tried going into HEPToolInstaller.py and changing the line;
_cpp = "g++"
to
_cpp = "g++ -std=c++11"
but that gets reset somehow when I actually run "install pythia8" from inside madgraph.

I tried changing the line then just calling HEPToolInstaller.py directly, and it did install pythia sucessfully, but it caused a cascade of problems starting with the mg5amc_py8_interface. So that is a no go.

Is there a correct way to specify additional flags for g++?
I am working on a cluster without administrative privileges, so I'm a bit limited in my ability to alter g++ itself.

Many thanks, Henry

Edit; for what it worth I just tried installing on my local machine and that worked without error.

Question information

Language:
English Edit question
Status:
Solved
For:
MadGraph5_aMC@NLO Edit question
Assignee:
No assignee Edit question
Solved by:
Olivier Mattelaer
Solved:
Last query:
Last reply:
Revision history for this message
Olivier Mattelaer (olivier-mattelaer) said :
#1

Hi,

What is your version of g++?

Can you check which version of pythia8, the code is trying to install?
In principle it should be 8.2.44 which should not need c++11 flag
but required a valid installation of boost.

So your issue might be with your installation of boost.

Cheers,

Olivier

> On 3 Mar 2021, at 12:35, Henry <email address hidden> wrote:
>
> New question #695834 on MadGraph5_aMC@NLO:
> https://answers.launchpad.net/mg5amcnlo/+question/695834
>
> I have downloaded the latest version of madgraph (to check if that will solve another issue) and I am trying to install pythia with the madgraph prompt. The installer runs into an error "Range-based 'for' loops are not allowed in C++98 mode". In theory this can be resolved by compiling with "-std=c++11".
>
> I tried going into HEPToolInstaller.py and changing the line;
> _cpp = "g++"
> to
> _cpp = "g++ -std=c++11"
> but that gets reset somehow when I actually run "install pythia8" from inside madgraph.
>
> I tried changing the line then just calling HEPToolInstaller.py directly, and it did install pythia sucessfully, but it caused a cascade of problems starting with the mg5amc_py8_interface. So that is a no go.
>
> Is there a correct way to specify additional flags for g++?
> I am working on a cluster without administrative privileges, so I'm a bit limited in my ability to alter g++ itself.
>
> Many thanks, Henry
>
> --
> You received this question notification because you are an answer
> contact for MadGraph5_aMC@NLO.

Revision history for this message
Henry (disreputabledog) said :
#2

Yes, my version of g++ is
```
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
```

The version of pythia it is trying to install is indeed 8.2.44.
The boost installation is without errors, so I don't think that is broken.

Also pythia will install with the -std=c++11 flag, which can be done by modifying and calling HEPToolInstaller.py directly, and the version that is install can run its example files and everything, so I think it's functional.

The first error in the log file is;
```
g++ -x c++ include/Pythia8Plugins/LHAPDF6.h -o tmp/LHAPDF6Plugin.o -c -MD -w -I/mainfs/scratch/hadh1g17/MG5_aMC_v2_9_2_bk/HEPTools/boost/include -I/mainfs/scratch/hadh1g17/MG5_aMC_v2_9_2/HEPTools/lhapdf6_py3/include -Iinclude -ldl -fPIC -lstdc++ -DHEPMC2HACK
In file included from /mainfs/scratch/hadh1g17/MG5_aMC_v2_9_2/HEPTools/lhapdf6_py3/include/LHAPDF/PDFInfo.h:10:0,
                 from /mainfs/scratch/hadh1g17/MG5_aMC_v2_9_2/HEPTools/lhapdf6_py3/include/LHAPDF/PDF.h:10,
                 from /mainfs/scratch/hadh1g17/MG5_aMC_v2_9_2/HEPTools/lhapdf6_py3/include/LHAPDF/LHAPDF.h:14,
                 from include/Pythia8Plugins/LHAPDF6.h:12:
/mainfs/scratch/hadh1g17/MG5_aMC_v2_9_2/HEPTools/lhapdf6_py3/include/LHAPDF/Info.h: In member function 'T LHAPDF::Info::get_entry_as(const string&) const [with T = std::vector<int>; std::string = std::basic_string<char>]':
/mainfs/scratch/hadh1g17/MG5_aMC_v2_9_2/HEPTools/lhapdf6_py3/include/LHAPDF/Info.h:189:28: error: range-based 'for' loops are not allowed in C++98 mode
     for (const string& s : strs) rtn.push_back( lexical_cast<int>(s) );
```

Revision history for this message
Best Olivier Mattelaer (olivier-mattelaer) said :
#3

Hi,

Your version of GCC is very old which does not make sense for a cluster.
You likely use the bare GCC installation while on cluster it is typically recommended to not use that compiler since dynamical library for that bare installation might not be the same on all node of the cluster.
I would suggest to try
module available GCC
to see if your cluster is using a module system.
Otherwise, please check the documentation of your cluster to see where/how you can use more recent version of compiler/library/...
In top of fixing a lot of compiling issue that you might face with that old compiler, you will also have a speed boost of your code thanks to the more performant compilation.

Cheers,

Olivier

Revision history for this message
Henry (disreputabledog) said :
#4

Yes, your right, there is a more recent version of g++ available, and switching to it solves all compilation issues.

Many thanks,
Henry

Revision history for this message
Henry (disreputabledog) said :
#5

Thanks Olivier Mattelaer, that solved my question.