Support for atomic in libstdc++ missing

Hi,

I think I have a problem with the installation of PGI 17.3, because simple atomic support is not working. I’m new to intalling PGI, so it will probably just be a stupid mistake on my side. The only clue I have is that PGI doesn’t understand the C++ library code. What C++ library is PGI supposed to work with?

Code:
#include
#include
#include “omp.h”

using std::cout;

int main (int argc, char *argv)
{
std::atomic accumulator(0);

#pragma omp parallel
{
accumulator++;
#pragma omp critical(out)
cout << "Thread " << omp_get_thread_num() << " of " << omp_get_num_threads() << ‘\n’;
}
cout << "Accumulator: " << accumulator << ‘\n’;
}

Error:
[stadler_h@merlin-l-01 C++]$ pgc++ -mp atomic.cc
“/afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/include/c++/6.4.0/bits/atomic
_base.h”, line 210: error: identifier
“__GCC_ATOMIC_TEST_AND_SET_TRUEVAL” is undefined
{ return __i ? __GCC_ATOMIC_TEST_AND_SET_TRUEVAL : 0; }

localrc file:
set LDSO=/lib64/ld-linux-x86-64.so.2;
set GCCDIR=/afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/bin/…/lib/gcc/x86_64-pc-linux-gnu/6.4.0;
set G77DIR=/afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/bin/…/lib/gcc/x86_64-pc-linux-gnu/6.4.0/;
set OEM_INFO=64-bit target on x86-64 Linux $INFOTPVAL;
set GCCINC= /afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/bin/…/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include /afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/bin/…/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include-fixed /usr/local/include /afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/bin/…/lib/gcc/…/…/include /usr/include;
set GPPDIR= /afs/psi.ch/sys/psi.merlin/Programming/pgi/17.3/linux86-64/17.3/include /afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/include/c++/6.4.0 /afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/include/c++/6.4.0/x86_64-pc-linux-gnu /afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/include/c++/6.4.0/backward /afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include /afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include-fixed /usr/local/include /afs/psi.ch/sys/psi.merlin/Programming/gcc/6.4.0/include /usr/include ;
set NUMALIBNAME=-lnuma ;
set LOCALRC=YES;
set THROW=__THROW=;
set EXTENSION=extension=;
set COMPGCCINCDIR=include-gcc60;
set LC=$if(-Bstatic,-lgcc -lgcc_eh -lc -lgcc -lgcc_eh -lc, -lgcc -lc -lgcc -lgcc_s);

GLIBC version 2.17

GCC version 6.4.0

set GCCVERSION=60400;
set LOCALDEFS=STDC_HOSTED;
set LIBNCURSES=YES;
export PGI=$COMPBASE;

makelocalrc executed by stadler_h Tue Sep 5 10:39:22

Hi,

I can make the code work by defining the __GCC_ATOMIC_TEST_AND_SET_TRUEVAL to 1, which looks like a sensible value on a x86_64 system. However, that’s not the way users would like it to have. Where is this macro normally defined and how is pgi supposed to pick it up?

PS: Compile command
pgc++ -D__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1 -mp atomic.cc -latomic

Hello,

For your code to compile, you must first be on a gcc system newer than
4.7 (which you have), you must set -std=c++11, and you need to
define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL as 1.


To not have to -D__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1
every time, create or edit a siterc file, either in your current directory
or home directory (or PGI bin directory).

pgc++ -dryrun foo.cc

will tell you if the siterc file gets read.

If you add the line
set PREOPTIONS=-D__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1;
( the semicolon is important!)
to the file, you can drop the
-D__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1
in the command line.


pgc++ -std=c++11 atomic.cc -mp -latomic

should now work.

dave

Thanks for the advice.

Does anyone know if there are other such macros that need to be set in order to have a smooth C++11 experience with PGI?

Our users here at PSI will for the major part not figure out for themselves what macros to set to which value - they’ll rather come to me and ask every time. So to be more efficient it would be nice to get a list of macros with values right away, ideally already as part of the installation.

HC

To get a list of defined macros

pgc++ -Wc,–list_macros example.cpp

dave

__GCC_ATOMIC_TEST_AND_SET_TRUEVAL is a built-in GCC macro. Depending on the command line options there are around 400–460 of them defined by GCC. Only God knows what PGI defines. I couldn’t get a list of predefined PGI macros using a usual gcc command line: “pgc++ -E -dM -x c++ -o defs.h - < /dev/null”. What I ended up doing is I got a list of gcc macros by invoking: “g++ -std=c++17 -E -dM -x c++ -o defs.h - < /dev/null”, then copy&pasted it into “include/_cplus_macros.h” in the PGI installation folder and then removed everything pgc++ complained on.