MathCancer / PhysiCell

PhysiCell: Scientist end users should use latest release! Developers please fork the development branch and submit PRs to the dev branch. Thanks!
http://PhysiCell.org
142 stars 95 forks source link

Fails to build with NVHPC 24.5 #236

Open fspiga opened 5 months ago

fspiga commented 5 months ago

Hello,

I am trying to build using NVIDIA C++ Compiler nvc++ version 24.5

CC := nvc++
CFLAGS := -O3 -fomit-frame-pointer -mp -std=c++11

It complains with the following error(s):

nvc++ -O3 -fomit-frame-pointer -mp -std=c++11  -o heterogeneity BioFVM_vector.o BioFVM_mesh.o BioFVM_microenvironment.o BioFVM_solvers.o BioFVM_matlab.o BioFVM_utilities.o BioFVM_basic_agent.o BioFVM_MultiCellDS.o BioFVM_agent_container.o   pugixml.o PhysiCell_phenotype.o PhysiCell_cell_container.o PhysiCell_standard_models.o PhysiCell_cell.o PhysiCell_custom.o PhysiCell_utilities.o PhysiCell_constants.o PhysiCell_basic_signaling.o PhysiCell_signal_behavior.o PhysiCell_rules.o PhysiCell_SVG.o PhysiCell_pathology.o PhysiCell_MultiCellDS.o PhysiCell_various_outputs.o PhysiCell_pugixml.o PhysiCell_settings.o PhysiCell_geometry.o custom.o main.cpp
main.cpp:
/usr/bin/ld: PhysiCell_constants.o: in function `__sti___30___core_PhysiCell_constants_cpp_d2e95040':
nvc++Ormxb4w0R0PHy.ll:(.text+0xb4): undefined reference to `PhysiCell::PhysiCell_constants::advanced_Ki67_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0xc4): undefined reference to `PhysiCell::PhysiCell_constants::advanced_Ki67_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x118): undefined reference to `PhysiCell::PhysiCell_constants::basic_Ki67_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x120): undefined reference to `PhysiCell::PhysiCell_constants::basic_Ki67_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x158): undefined reference to `PhysiCell::PhysiCell_constants::flow_cytometry_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x164): undefined reference to `PhysiCell::PhysiCell_constants::live_cells_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x19c): undefined reference to `PhysiCell::PhysiCell_constants::flow_cytometry_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x1c8): undefined reference to `PhysiCell::PhysiCell_constants::live_cells_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x1f8): undefined reference to `PhysiCell::PhysiCell_constants::flow_cytometry_separated_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x234): undefined reference to `PhysiCell::PhysiCell_constants::flow_cytometry_separated_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x268): undefined reference to `PhysiCell::PhysiCell_constants::cycling_quiescent_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x274): undefined reference to `PhysiCell::PhysiCell_constants::apoptosis_death_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x278): undefined reference to `PhysiCell::PhysiCell_constants::necrosis_death_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x2b4): undefined reference to `PhysiCell::PhysiCell_constants::cycling_quiescent_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x2e0): undefined reference to `PhysiCell::PhysiCell_constants::apoptosis_death_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x30c): undefined reference to `PhysiCell::PhysiCell_constants::advanced_Ki67_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x310): undefined reference to `PhysiCell::PhysiCell_constants::necrosis_death_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x34c): undefined reference to `PhysiCell::PhysiCell_constants::advanced_Ki67_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x370): undefined reference to `PhysiCell::PhysiCell_constants::basic_Ki67_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x378): undefined reference to `PhysiCell::PhysiCell_constants::basic_Ki67_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x3f4): undefined reference to `PhysiCell::PhysiCell_constants::flow_cytometry_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x3f8): undefined reference to `PhysiCell::PhysiCell_constants::flow_cytometry_cycle_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x508): undefined reference to `PhysiCell::PhysiCell_constants::cycling_quiescent_model'
/usr/bin/ld: nvc++Ormxb4w0R0PHy.ll:(.text+0x514): undefined reference to `PhysiCell::PhysiCell_constants::cycling_quiescent_model'
pgacclnk: child process exit status 1: /usr/bin/ld
make: *** [Makefile:71: all] Error 2

I consulted NVIDIA compiler engineer. It looks like the code is not super portable. The file core/PhysiCell_constants.h contains many static data members of type const int, such as:

namespace PhysiCell
{
class PhysiCell_constants
{
 public:
        // ...
        static const int advanced_Ki67_cycle_model= 0;
        // ...
};
};

Each of those static data members must have an out-of-class definition in a .cpp file somewhere, so that storage for the static data member exists somewhere:

namespace PhysiCell {
const int PhysiCell_constants::advanced_Ki67_cycle_model;
}

In some cases the compiler can do constant folding and optimize away references to the static data member, in which case the code can get away without the definition. With -O3 GNU seems to work. With lower optimisation flags, it may complain too. nvc++ is unable to do the constant folding in this particular situation,

It would be best if the code becomes more robust, so that PhysiCell_constants.cpp contained definitions for all the static data members of class PhysiCell_constants. That will make the code able to build in more situations and with more compilers with different optimisation levels.

rheiland commented 5 months ago

Would you please try using the .h, .cpp versions here? https://github.com/rheiland/PhysiCell/tree/dev-constants/core

vincent-noel commented 5 months ago

I had someone from Barcelona Supercomputing Center commenting on this, who even submitted a PR to our PhysiBoSS repo. I ended up telling him the PR should be here and closing it (https://github.com/PhysiBoSS/PhysiBoSS/pull/3), but this was his fix: https://github.com/PhysiBoSS/PhysiBoSS/pull/3/commits/eafaa8c9dce61bc4f6ff8eb6b4f18cd9b2887acc