Passing Conduit Nodes between C++, Fortran, and Python

The cpp_fort_and_py example demonstrates how to pass Conduit Nodes between C++, Fortran, and Python. It is a standalone example that you can build with CMake against your Conduit install.

You can find this example under src/examples/cpp_fort_and_py in Conduit’s source tree, or under examples/conduit/cpp_fort_and_py in a Conduit install.

It includes source for an embedded python interpreter and also shows how to create a Fortran module that binds Conduit Nodes via Conduit’s C-API.

It creates two executables:

conduit_cpp_and_py_ex Demo of C++ to Python and vice versa
conduit_fort_and_py_ex Demo of Fortran to Python and vice versa

This demos wrapping Conduit Nodes, effectively creating referenced data across languages. You can also use set_external to directly access and change zero-copied data.

Please see the main CMakeList.txt file for details on building and running:

cpp_fort_and_py/CMakeLists.txt excerpt:

Example that shows how to use Conduit across C++, Fortran, and an
embedded Python interpreter.


Building:

Note: The python instance must have the conduit python module installed
or it must be in your PYTHONPATH.

> mkdir build
> cd build

# if conduit python module is not installed in your python instance
# > export PYTHONPATH=/path/to/conduit-install/python-modules

> cmake  \
   -DCONDUIT_DIR=/path/to/conduit/install
   -DPYTHON_EXECUTABLE=/path/to/python/bin/python
   ../
> make


Running:
> ./conduit_cpp_and_py_ex
> ./conduit_fort_and_py_ex

# if conduit python module is not installed in your python instance
> env PYTHONPATH=/path/to/conduit-install/python-modules  ./conduit_cpp_and_py_ex
> env PYTHONPATH=/path/to/conduit-install/python-modules  ./conduit_fort_and_py_ex