Skip to content

Instantly share code, notes, and snippets.

@kdheepak
Created January 17, 2019 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdheepak/7094377e1df06786f7acc987a587a35d to your computer and use it in GitHub Desktop.
Save kdheepak/7094377e1df06786f7acc987a587a35d to your computer and use it in GitHub Desktop.
Build GridLAB-D with HELICS, Boost and ZeroMQ using GCC on MacOSX

Install gcc

Install gcc using brew

brew install gcc

Install Boost

Bootstrap boost

curl -LO https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
tar -xvf boost_1_69.0.tar.gz
cd boost_1_69_0
./bootstrap.sh --prefix=/Users/$USER/local/boost-gcc-1.69.0
vim project-config.jam

Edit project-config.jam to add the lines shown with a + and remove the lines shown with a -.

  # Compiler configuration. This definition will be used unless
  # you already have defined some toolsets in your user-config.jam
  # file.
- if ! darwin in [ feature.values <toolset> ]
- {
-   # using darwin ;
- }
-
- project : default-build <toolset>darwin ;
+ # if ! darwin in [ feature.values <toolset> ]
+ # {
+     # using darwin ;
+ # }
+ #
+ # project : default-build <toolset>darwin ;
+
+ using gcc : 8.2 : /usr/local/Cellar/gcc/8.2.0/bin/g++-8 ;

Install boost

./b2 link=static cxxflags='-fPIC -std=c++17' cflags=-fPIC -a install

Install HELICS

Install HELICS from source

git clone git@github.com:GMLC-TDC/HELICS-src.git
cd HELICS-src
git checkout 79a44586ea97c45cbdd527a639a404f8589d634b # develop
mkdir build-osx
cd build-osx
cmake -DCMAKE_INSTALL_PREFIX="/Users/$USER/local/helics-gcc-2.0.0/" -DBOOST_ROOT="/Users/$USER/local/boost-gcc-1.69.0" -DCMAKE_C_COMPILER=/usr/local/Cellar/gcc/8.2.0/bin/gcc-8 -DCMAKE_CXX_COMPILER=/usr/local/Cellar/gcc/8.2.0/bin/g++-8 -DZMQ_USE_STATIC_LIBRARY=ON -DUSE_BOOST_STATIC_LIBS=ON -DCMAKE_EXE_LINKER_FLAGS="-Bstatic" ../
make -j 8 && make install

Install GridLAB-D

Install GridLAB-D from source

git clone git@github.com:gridlab-d/gridlab-d.git
cd gridlab-d
git checkout e8ec2c437fdb1e4e9d4e455190258b93cb18f15a # feature/1153
vim configure.ac

Edit configure.ac to add the lines shown with a + and remove the lines shown with a -.

  m4_define([sbuild_m4_chomp],
  @ configure.ac:499 @ gld_save_CPPFLAGS="$CPPFLAGS"; CPPFLAGS="$CPPFLAGS $HELICS_CPPFLAGS"
  # add libhelics to HELICS_LIBS if missing
  AS_CASE([$host],
      [*linux*], [AS_CASE([$HELICS_LIBS],
                      [*lhelics*], [], [HELICS_LIBS="$HELICS_LIBS -lhelics-static -lrt -lzmq -lboost_filesystem -lboost_program_options -lboost_system -lboost_unit_test_framework"])
                  AS_CASE([$LIBS],
                      [*lhelics*], [], [LIBS="$LIBS -lhelics-static -lrt -lzmq -lboost_filesystem -lboost_program_options -lboost_system -lboost_unit_test_framework"])],
      [*darwin*], [AS_CASE([$HELICS_LIBS],
-                     [*lhelics*], [], [HELICS_LIBS="$HELICS_LIBS -lhelics-static -lrt -lzmq -lboost_filesystem -lboost_program_options -lboost_system -lboost_unit_test_framework"])
+                     [*lhelics*], [], [HELICS_LIBS="$HELICS_LIBS -Wl,-rpath,/Users/$USER/local/helics-gcc-2.0.0/lib/ -L/Users/$USER/local/helics-gcc-2.0.0/lib/ -lhelicsSharedLib"])
                  AS_CASE([$LIBS],
-                     [*lhelics*], [], [LIBS="$LIBS -lhelics-static -lrt -lzmq -lboost_filesystem -lboost_program_options -lboost_system -lboost_unit_test_framework"])],
+                     [*lhelics*], [], [LIBS="$LIBS -Wl,-rpath,/Users/$USER/local/helics-gcc-2.0.0/lib/ -L/Users/$USER/local/helics-gcc-2.0.0/lib/ -lhelicsSharedLib"])],
      [*mingw*], [AS_CASE([$HELICS_LIBS],
                      [*lhelics*], [], [HELICS_LIBS="$HELICS_LIBS -lhelics-static -lrt -lzmq -lboost_filesystem-mt -lboost_program_options-mt -lboost_system-mt -lboost_unit_test_framework-mt"])
                  AS_CASE([$LIBS],
                      [*lhelics*], [], [LIBS="$LIBS -lhelics-static -lrt -lzmq -lboost_filesystem-mt -lboost_program_options-mt -lboost_system-mt -lboost_unit_test_framework-mt"])])
  have_helics=yes
  AC_MSG_CHECKING([for HELICS])
  AC_LINK_IFELSE(
  @ configure.ac:517 @ AC_LINK_IFELSE(
  #include <helics/application_api/helicsTypes.hpp>
  ]],
  [[
- helics::named_point t;
+ helics::NamedPoint t;
  ]])],
      [have_helics=yes; have_helics_int=1],
      [have_helics=no; have_helics_int=0])
  @ configure.ac:620 @ AC_SUBST([MATLAB_CPPFLAGS])
  AC_SUBST([MATLAB_LDFLAGS])
  AC_SUBST([MATLAB_LDPATH])
  AC_SUBST([MATLAB_LIBS])

Configure GridLAB-D installation, install and validate

autoreconf -isf && ./configure --prefix=/Users/$USER/local/gridlabd-gcc-develop/ --with-helics=/Users/$USER/local/helics-gcc-2.0.0/ --enable-silent-rules CC='gcc-8' CXX='g++-8' CFLAGS='-g -O0 -w' CXXFLAGS='-g -O0 -w -std=c++14' LDFLAGS='-g -O0 -w'
make -j8
make install
/Users/$USER/local/gridlabd-gcc-develop/bin/gridlabd.sh --validate
cd ..

Test GridLAB-D built with GCC and with helics on Mac

git clone git@github.com:GMLC-TDC/HELICS-Tutorial.git
cd HELICS-Tutorial/test_system_data/gldFeeders/B2/G_1
/Users/$USER/local/gridlabd-gcc-develop/bin/gridlabd.sh DistributionSim_B2_G_1.glm
cd HELICS-Tutorial/test_system_data/gldFeeders/B2/G_1
helics_broker -f 1 --loglevel=7
@trevorhardy
Copy link

I think this could work as something we put in the installation instructions. We'll need to figure out how to generalize the pathing so that users don't get confused. Maybe setting up some environment variables for the locations of boost, gcc, HELICS, and GridLAB-D and using those in the instructions?

Relatedly, the last line should be:

/Users/$USER/local/helics-gcc-2.0.0/helics_broker -f 1 --loglevel=7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment