Linux Create and Debug Model

From OpenM++
Jump to: navigation, search


What do you need

Optional: Before you begin

If you want to debug your model then you will need to rebuild openM++ runtime library first as described at Linux Quick Start for Developers

To build and run debug version of the model use desktop (non-MPI) version of openM++:

tar xzf openmpp_centos_20180205.tar.gz
cd openmpp_centos_20180205/openm/
make libopenm

Create New Model

  • create new directory for your model under models subfolder i.e.: models/MyModel
  • copy other test model makefile into your model folder, copy your model files and data files:
cd openmpp_centos_20180205/models/
mkdir MyModel
cd MyModel
cp ../NewCaseBased/makefile .
mkdir code
cp ~/my_model_sources/*mpp code
cp ~/my_model_sources/*.cpp code
cp ~/my_model_sources/*.h code
mkdir -p parameters/Default
cp ~/my_model_data/*dat parameters/Default
  • build your model:
make PUBLISH_DIR=ompp-linux/bin model publish
  • run the model:
cd ompp-linux/bin

Please note: It is recommended (not required) to have directory name exactly the same as model name. Linux file and directory names are case-sensitive and myModel is not the same as MyModel

Debug your Model

Below example of debugging the model using NetBeans and very similar instructions applied to other IDEs, i.e.: Eclipse.

  • start NetBeans and create new project with existing ~/openmpp_centos_20180205/models/MyModel/makefile
  • build the project (NetBeans may build new project automatically upon creation, if result successful then go to next)

You need to specify path to the model SQLite database, which by default located in "current model directory" and must have file name

  • open your Project -> Properties -> Build -> Make and change:
    • Build Command: ${MAKE} -f makefile PUBLISH_DIR=ompp-linux/bin model publish
    • Clean Command: ${MAKE} -f makefile PUBLISH_DIR=ompp-linux/bin cleanall
  • change Project -> Properties -> Debug:
    • Debug Command: "${OUTPUT_PATH}" -OpenM.Database Database="${OUTPUT_PATH}.sqlite;Timeout=86400;OpenMode=ReadWrite"

Set Make commands in NetBeans
Set Make commands in NetBeans

Set Debug command in NetBeans
Set Make commands to debug MyModel in NetBeans

Now you must rebuild your model and after that can start debugging:

  • clean and build the project
  • open file MyModel/ompp-linux/build/debug/src/om_definitions.cpp
  • put breakpoint at RunModel function and start debugging
  • there are other entry points to your modeling code at om_definitions.cpp:
    • RunOnce
    • RunInit
    • ModelStartup
    • ModelShutdown
Debug model using NetBeans
Debug model using NetBeans

It is also possible to open file ../openm/libopenm/main.cpp and debug from main()</main>:

Debug model using NetBeans
Debug model using NetBeans

<metadesc>OpenM++: open source microsimulation platform</metadesc>