Error on TBufferFile::ReadVersion

Are you using “nvcc” to build it?
If yes, try to work without CUDA.

Check the “nvcc --version” as maybe it internally uses a “g++” version, which is different from the system’s one.

You should also check what this returns (we are looking for the “__BYTE_ORDER__”):
: | nvcc -dM -E -x c++ - | grep -i endian

Try to compile this with “nvcc” (it also prints the actually used “g++” version):

// Usage: nvcc -std=c++11 main.cxx; ./a.out
#include <iostream>
int main() {
   std::cout << "__BYTE_ORDER__ = " << (__BYTE_ORDER__) << "\n";
   std::cout << "__ORDER_LITTLE_ENDIAN__ = " << (__ORDER_LITTLE_ENDIAN__) << "\n";
   std::cout << "__ORDER_BIG_ENDIAN__ = " << (__ORDER_BIG_ENDIAN__) << "\n";
   std::cout << "__VERSION__ = " << (__VERSION__) << "\n";
   std::cout << "__cplusplus = " << (__cplusplus) << "\n";
   return 0;
}

BTW. In your makefile, I would set “CXX = $(shell root-config --cxx)” and then use “$(CXX)” instead of “g++”. Also, in the places where it is used, I would temporarily add a line with “$(CXX) --version” (to make sure that it is exactly the same compiler that was used by ROOT).

We do load cuda to compile a sepeatate CUDA package:

[wshi@login3.summit MaCh3]$ module load cuda/11.5.2
[wshi@login3.summit MaCh3]$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:46:07_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

Here is the endianess:

[wshi@login3.summit MaCh3]$ : | nvcc -dM -E -x c++ - | grep -i endian
nvcc fatal   : Unknown option '-dM'
[wshi@login3.summit ~]$ : | nvcc --compiler-options -dM -E -x c++ - | grep -i endian
#define __ORDER_LITTLE_ENDIAN__ 1234
#define _LITTLE_ENDIAN 1
#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __ORDER_PDP_ENDIAN__ 3412
#define __LITTLE_ENDIAN__ 1
#define __ORDER_BIG_ENDIAN__ 4321
#define __VEC_ELEMENT_REG_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__

And the nvcc g++ version (the system gcc version is 8.3.1)

[wshi@login3.summit ~]$ nvcc -std=c++11 main.cxx; ./a.out
__BYTE_ORDER__ = 1234
__ORDER_LITTLE_ENDIAN__ = 1234
__ORDER_BIG_ENDIAN__ = 4321
__VERSION__ = 8.3.1 20191121 (Red Hat 8.3.1-5)
__cplusplus = 201103

So, it looks like “nvcc” calls the right “g++”.

Maybe attach the “inputs/skatm/OscillogramTemplate.root” file for inspection.

I guess we need @pcanal for a closer look.

Here:
OscillogramTemplate.root (25.5 KB)

In your “test.C”, change “void test()” into “int main()” and then make two trials:

rm -f a.out
`root-config --cxx --cflags` test.C `root-config --libs`
./a.out
rm -f a.out
nvcc `root-config --cflags` test.C `root-config --libs`
./a.out

If both work, in the “nvcc” line, remove the ROOT “cflags” and try to add the same flags as used in your makefile.

Actually, I can’t find the real “main” routine of your “OscClass” executable.
Right in its beginning, try to add one line:
TApplication a("a", 0, 0); // just to make sure that the autoloading of ROOT libraries works

So the first line works, the 2nd doesn’t:

[wshi@login1.summit ~]$ `root-config --cxx --cflags` test.C `root-config --libs`
[wshi@login1.summit ~]$ ./a.out
Read Oscillator Template file (InputFileName): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
Read Oscillator Template file (InputFileName.c_str()): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
nCoarseCosz: 52
[wshi@login1.summit ~]$ rm -f a.out

[wshi@login1.summit ~]$ nvcc `root-config --cflags` test.C `root-config --libs`
nvcc fatal   : Unknown option '-pthread'
[wshi@login1.summit ~]$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:46:07_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

So, from the “root-config --cflags” output, remove “-pthread”.

Ok, that didn’t work:

[wshi@login1.summit ~]$ root-config --cflags
-pthread -std=c++11 -Wno-deprecated-declarations -m64 -fsigned-char -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include
[wshi@login1.summit ~]$ root-config --libs
-L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic
[wshi@login1.summit ~]$ nvcc `root-config --cflags` test.C `root-config --libs`
nvcc fatal   : Unknown option '-pthread'
[wshi@login1.summit ~]$ nvcc -std=c++11 -Wno-deprecated-declarations -m64 -fsigned-char -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include test.C -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic
nvcc fatal   : Unknown option '-fsigned-char'
[wshi@login1.summit ~]$ nvcc -std=c++11 -Wno-deprecated-declarations -m64 -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include test.C -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic
nvcc fatal   : Unknown option '-pthread'
[wshi@login1.summit ~]$ nvcc -std=c++11 -Wno-deprecated-declarations -m64 -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include test.C -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lm -ldl -rdynamic
nvcc fatal   : Unknown option '-rdynamic'
[wshi@login1.summit ~]$ nvcc -std=c++11 -Wno-deprecated-declarations -m64 -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include test.C -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lm -ldl          
nvcc fatal   : Don't know what to do with 'test.C'

Maybe it doesn’t know “.C” files. Try to rename it into “test.cxx”.

That worked

[wshi@login1.summit ~]$ nvcc -std=c++11 -Wno-deprecated-declarations -m64 -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include test.cxx -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lm -ldl 
[wshi@login1.summit ~]$ ./a.out 
Read Oscillator Template file (InputFileName): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
Read Oscillator Template file (InputFileName.c_str()): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
nCoarseCosz: 52

Then I tried to remove the root cflags and use the makefile cxx flag: CXXFLAGS = -I. -Wall -fPIC -O3 -g -std=c++11 -fopenmp, it complains no TH2D:

[wshi@login1.summit ~]$ nvcc -I. -Wall -fPIC -O3 -g -std=c++11 -fopenmp test.cxx -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lm -ldl 
nvcc fatal   : Unknown option '-Wall'
[wshi@login1.summit ~]$ nvcc -I. -fPIC -O3 -g -std=c++11 -fopenmp test.cxx -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lm -ldl 
nvcc fatal   : Unknown option '-fPIC'
[wshi@login1.summit ~]$ nvcc -I. -O3 -g -std=c++11 -fopenmp test.cxx -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lm -ldl 
nvcc fatal   : Unknown option '-fopenmp'
[wshi@login1.summit ~]$ nvcc -I. -O3 -g -std=c++11  test.cxx -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lm -ldl 
test.cxx:1:10: fatal error: TH2D.h: No such file or directory
 #include "TH2D.h"
          ^~~~~~~~
compilation terminated.

Add, e.g.: -I${ROOTSYS}/include

Ok, this worked

[wshi@login1.summit ~]$ nvcc -I. -O3 -g -std=c++11 -I${ROOTSYS}/include  test.cxx -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lm -ldl 
[wshi@login1.summit ~]$ ./a.out 
Read Oscillator Template file (InputFileName): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
Read Oscillator Template file (InputFileName.c_str()): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
nCoarseCosz: 52

So is this saying I should either avoid loading cuda, or change the make file to use the above rule to compile with nvcc?

Well, in the last trial, try to add “-x cu” (which exists in your makefile and it enforces the file type).

Somehow, you need to “reproduce” the error.
The first trial would be to modify the makefile so that it always uses “${CXX}”, also when CUDA is loaded.
If it works, you can try to play with the “nvcc” command line there.

This also worked

[wshi@login1.summit ~]$ nvcc -I. -O3 -x cu -g -std=c++11 -I${ROOTSYS}/include  test.cxx -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lm -ldl 
[wshi@login1.summit ~]$ ./a.out 
Read Oscillator Template file (InputFileName): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
Read Oscillator Template file (InputFileName.c_str()): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
nCoarseCosz: 52

The compile part of this executable is here:
Osc.txt (3.6 KB)

I am using the exact same rule to compile test.cxx

nvcc -g -O3 -x cu  -lineinfo -std=c++11 -Xcompiler="-fopenmp -Wall -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lRooFit -lRooFitCore -lMinuit -lHistPainter -I. -Wall -fPIC -O3 -g -std=c++11 -fopenmp -DUSE_GPU" test.cxx

And it worked fine

[wshi@login1.summit ~]$ nvcc -g -O3 -x cu  -lineinfo -std=c++11 -Xcompiler="-fopenmp -Wall -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lRooFit -lRooFitCore -lMinuit -lHistPainter -I. -Wall -fPIC -O3 -g -std=c++11 -fopenmp -DUSE_GPU" test.cxx
[wshi@login1.summit ~]$ ./a.out 

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

Read Oscillator Template file (InputFileName): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
Read Oscillator Template file (InputFileName.c_str()): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
nCoarseCosz: 52

I think this is “mandatory”:

I added it like this:

#include "OscClass_CUDAProb3.h"

Oscillator::Oscillator(std::string ConfigName) {

TApplication a(“a”, 0, 0);

  //####################################################################################
  //Set definite values
  
  nOscpars = 6;

Here is what it says

make[1]: Entering directory '/autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/OscClass'
rm -f OscClass_CUDAProb3.o
nvcc -g -O3 -x cu  -lineinfo -std=c++11 -Xcompiler="-fopenmp -Wall -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include -L/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lRooFit -lRooFitCore -lMinuit -lHistPainter -I. -Wall -fPIC -O3 -g -std=c++11 -fopenmp -pthread -std=c++11 -Wno-deprecated-declarations -m64 -fsigned-char -I/autofs/nccs-svm1_home1/wshi/ROOT/v5-34-00-patches/include -DUSE_GPU" -I.. -c OscClass_CUDAProb3.cpp -o OscClass_CUDAProb3.o
OscClass_CUDAProb3.cpp(5): error: identifier "TApplication" is undefined

1 error detected in the compilation of "OscClass_CUDAProb3.cpp".
make[1]: *** [Makefile:58: OscClass_CUDAProb3.o] Error 1
make[1]: Leaving directory '/autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/OscClass'
make: *** [Makefile:52: all] Error 2

You need to find the “main” routine of your executable:

#include "TApplication.h"
int main(int argc, char **argv) {
  TApplication a("a", 0, 0); // just to make sure that the autoloading of ROOT libraries works
  // ... the current content of the main comes here ...
}

what do I expect after adding this? I added in the main function below and I still see the same error, there is no obvious change.
PrintEventRate.cpp (30.0 KB)

I also need to point out in the very first post of this topic, even though I loaded a cuda module, the executable is not built with nvcc (I didn’t define $CUDAPATH when compile), instead, the executable is built with g++ (so this is not a nvcc problem):

make[1]: Entering directory '/autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/OscClass'
g++ -I. -Wall -fPIC -O3 -g -std=c++11 -fopenmp -I/autofs/nccs-svm1_home1/wshi/ProdROOT/v5-34-00-patches/include -L/autofs/nccs-svm1_home1/wshi/ProdROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lRooFit -lRooFitCore -lMinuit -lHistPainter -I.. -c OscClass_CUDAProb3.cpp -o OscClass_CUDAProb3.o
In file included from ../manager/manager.h:17,
                 from OscClass_CUDAProb3.h:15,
                 from OscClass_CUDAProb3.cpp:1:
../libconfig/lib/libconfig.h++:200:36: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
   void assertType(Type type) const throw(SettingTypeException);
                                    ^~~~~
In file included from OscClass_CUDAProb3.h:19,
                 from OscClass_CUDAProb3.cpp:1:
../CUDAProb3/propagator.hpp: In instantiation of 'void cudaprob3::Propagator<FLOAT_T>::setProductionHeightList(const std::vector<FLOAT_T>&, const std::vector<FLOAT_T>&) [with FLOAT_T = double]':
OscClass_CUDAProb3.cpp:1488:93:   required from here
../CUDAProb3/propagator.hpp:504:30: warning: comparison of integer expressions of different signedness: 'std::vector<double>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
         if (list_prob.size() != this->nProductionHeightBins*2*3*n_energies*n_cosines) {
../CUDAProb3/propagator.hpp:508:32: warning: comparison of integer expressions of different signedness: 'std::vector<double>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
         if (list_bins.size()-1 != this->nProductionHeightBins) {
../CUDAProb3/propagator.hpp:514:32: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
         for (unsigned int i=0;i<MaxSize;i++) {
                               ~^~~~~~~~
In file included from OscClass_CUDAProb3.h:27,
                 from OscClass_CUDAProb3.cpp:1:
../CUDAProb3/cpupropagator.hpp: In instantiation of 'void cudaprob3::CpuPropagator<FLOAT_T>::setChemicalComposition(const std::vector<FLOAT_T>&) [with FLOAT_T = double]':
../CUDAProb3/cpupropagator.hpp:117:14:   required from here
../CUDAProb3/cpupropagator.hpp:122:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
           for (int iyp=0;iyp<list.size();iyp++) {
../CUDAProb3/cpupropagator.hpp: In instantiation of 'void cudaprob3::CpuPropagator<FLOAT_T>::getProbabilityArr(FLOAT_T*, cudaprob3::ProbType) [with FLOAT_T = double]':
../CUDAProb3/cpupropagator.hpp:138:14:   required from here
../CUDAProb3/cpupropagator.hpp:141:57: warning: comparison of integer expressions of different signedness: 'uint64_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
           for (std::uint64_t index_energy=0;index_energy<this->n_energies;index_energy++) {
                                             ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
../CUDAProb3/cpupropagator.hpp:142:59: warning: comparison of integer expressions of different signedness: 'uint64_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
             for (std::uint64_t index_cosine=0;index_cosine<this->n_cosines;index_cosine++) {
                                               ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
g++ -shared -o libOscillator_1.00.so OscClass_CUDAProb3.o -L/autofs/nccs-svm1_home1/wshi/ProdROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lRooFit -lRooFitCore -lMinuit -lHistPainter
mv libOscillator_1.00.so ../lib/.
make[1]: Leaving directory '/autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/OscClass'

Use the same g++ rule to compile test.cxx, I got the expected output.

[wshi@login5.summit ~]$ g++ -I. -Wall -fPIC -O3 -g -std=c++11 -fopenmp -I/autofs/nccs-svm1_home1/wshi/ProdROOT/v5-34-00-patches/include -L/autofs/nccs-svm1_home1/wshi/ProdROOT/v5-34-00-patches/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lRooFit -lRooFitCore -lMinuit -lHistPainter test.cxx                                              
[wshi@login5.summit ~]$ ./a.out 

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

Read Oscillator Template file (InputFileName): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
Read Oscillator Template file (InputFileName.c_str()): /autofs/nccs-svm1_home1/wshi/MaCh3/MaCh3/inputs/skatm/OscillogramTemplate.root
nCoarseCosz: 52