ODE (Runge-Kutta 4, etc.) from GSL or boost from inside ROOT interactive session

I would like to run ODE (Runge-Kutta 4, etc.) from GSL or boost from inside ROOT interactive session or to have tools/classes to do it in a way similar to Matlab.
*As far as I remember the proposal to include Runge-Kutta to TMath is awaiting for since back to 2003
“Proposal for a C++ mathlib”

Hi @xtovo ,
I took the liberty to move this discussion to a new topic. Since the switch to cling with ROOT6 a few years ago, arbitrary C++ can be executed at the ROOT prompt, including complex templated code.

Can you please share an example of what you’d like to do and how exactly it fails?
Cheers,
Enrico

Regarding:

Let me give the bad news for you: that ain’t gonna happen :slight_smile: Please use one of the existing C++ libraries and let us know what fails and how, as @eguiraud recommends!

Hi Enrico,
I’m just a stupid ROOT user.
I’m just wanna solve a simple car-moving problem via
ordinary differential equation dx/dt = v with boost::numeric::odeint
from inside the ROOT interactive shell.

Could you help me with an example how to do it?

Thanks.
Regards. Valeriy

++
Sorry, probably I’m wrong.
I just didn’t know that it’s already easy & straightforward and believed that
a new brave LLVM Clang-Repl is the huge step in this direction.

In fact, recently I found two exciting publications about “beer physics”:

and decided to prepare a physical lab (with ROOT & beer inside) based on this material for my students.
I desperately need ODE tool for that.

So, I installed boost via my package manager and followed the first few steps of the boost::numeric::odeint short example. As far as I can tell it works out of the box:

~ root -l
root [0] #include <boost/numeric/odeint.hpp>
root [1] using namespace boost::numeric::odeint;
root [2] typedef std::vector< double > state_type;
root [3] const double gam = 0.15;
root [4] void harmonic_oscillator( const state_type &x , state_type &dxdt , const double /* t */ ) {
root (cont'ed, cancel with .@) [5]dxdt[0] = x[1];
root (cont'ed, cancel with .@) [6]dxdt[1] = -x[0] - gam*x[1];
root (cont'ed, cancel with .@) [7]}
root [8] state_type x(2);
root [9] x[0] = 1.0;
root [10] x[1] = 0.0;
root [11] size_t steps = integrate( harmonic_oscillator , x , 0.0 , 10.0 , 0.1 );

Let us know if you encounter any issue.
Cheers,
Enrico

This might be a good usecase for C++ Jupyter notebooks, especially if you can use ROOT v6.24 where the C++ interpreter allows redefinition of variables and functions (so you can re-execute a notebook cell without getting a compilation error).

If you get around to it, let us know how the lab goes :slight_smile:

Hi Enrico,
sorry for my stupidity.
I installed D:\boost_1_74_0
What to do next?
How to add boost to ROOT env vars: includes, libs?
Where can I find HOWTOs?

Thanks.
Regards. Valeriy

++
Could you reveal a magic of " I installed boost via my package manager "?

Any news?

That’s slightly passive aggressive, please assume that I’m doing my best to help out :confused:

I’m on Arch linux, so pacman -Syu boost installed all boost libraries in the usual system location where compilers look for includes and shared libs.

If you installed boost in a non-standard location, you can use gSystem->AddIncludePath to tell ROOT to look in that location too, and then you can just #include <...> the boost header. If it’s a header-only library that’s all you need to do, otherwise you might also have to load the library. There is an example e.g. here (Python, but translates 1:1 to C++) but you’ll also find many on the forum.

Cheers,
Enrico

Hi Valeriy,
Since you’re working on Windows, just type set INCLUDE=D:\boost_1_74_0;%INCLUDE% before starting ROOT, or add it in your environment variables. Then you can try the example posted by @eguiraud

1 Like

I re-installed boost with (in default location)

choco install boost-msvc-14.2
added
BOOST_ROOT = “C:\local\boost_1_74_0”
INCLUDE= %BOOST_ROOT%;%INCLUDE%

root -l


| Welcome to ROOT 6.25/01 https://root.cern |
| (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for win32 on Apr 11 2021, 11:06:33 |
| From heads/master@v6-25-01-596-gdf70fffe7e |
| With MSVC 19.28.29913.0 |

Try ‘.help’, ‘.demo’, ‘.license’, ‘.credits’, ‘.quit’/’.q’

root [0]
root [0] gSystem->AddIncludePath(“C:\local\boost_1_74_0”)
root [1] #include <boost/numeric/odeint.hpp>
In file included from ROOT_prompt_1:1:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint.hpp:25:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/util/ublas_wrapper.hpp:30:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/algebra/default_operations.hpp:24:
In file included from C:\local\boost_1_74_0\boost/array.hpp:48:
In file included from C:\local\boost_1_74_0\boost/swap.hpp:15:
C:\local\boost_1_74_0\boost/core/swap.hpp:41:3: error: unknown type name ‘host
BOOST_GPU_ENABLED
^
C:\local\boost_1_74_0\boost/config/compiler/nvcc.hpp:23:27: note: expanded from macro ‘BOOST_GPU_ENABLED’
#define BOOST_GPU_ENABLED host device
^
In file included from ROOT_prompt_1:1:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint.hpp:25:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/util/ublas_wrapper.hpp:30:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/algebra/default_operations.hpp:24:
In file included from C:\local\boost_1_74_0\boost/array.hpp:48:
In file included from C:\local\boost_1_74_0\boost/swap.hpp:15:
C:\local\boost_1_74_0\boost/core/swap.hpp:41:20: error: expected ‘;’ at end of declaration
BOOST_GPU_ENABLED
^
C:\local\boost_1_74_0\boost/core/swap.hpp:42:18: error: unknown type name ‘T’
void swap_impl(T& left, T& right)
^
C:\local\boost_1_74_0\boost/core/swap.hpp:42:27: error: unknown type name ‘T’
void swap_impl(T& left, T& right)
^
C:\local\boost_1_74_0\boost/core/swap.hpp:49:3: error: unknown type name ‘host
BOOST_GPU_ENABLED
^
C:\local\boost_1_74_0\boost/config/compiler/nvcc.hpp:23:27: note: expanded from macro ‘BOOST_GPU_ENABLED’
#define BOOST_GPU_ENABLED host device
^
In file included from ROOT_prompt_1:1:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint.hpp:25:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/util/ublas_wrapper.hpp:30:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/algebra/default_operations.hpp:24:
In file included from C:\local\boost_1_74_0\boost/array.hpp:48:
In file included from C:\local\boost_1_74_0\boost/swap.hpp:15:
C:\local\boost_1_74_0\boost/core/swap.hpp:49:20: error: expected ‘;’ at end of declaration
BOOST_GPU_ENABLED
^
C:\local\boost_1_74_0\boost/core/swap.hpp:50:8: error: variable has incomplete type ‘void’
void swap_impl(T (& left)[N], T (& right)[N])
^
C:\local\boost_1_74_0\boost/core/swap.hpp:50:18: error: use of undeclared identifier ‘T’
void swap_impl(T (& left)[N], T (& right)[N])
^
C:\local\boost_1_74_0\boost/core/swap.hpp:50:29: error: use of undeclared identifier ‘N’
void swap_impl(T (& left)[N], T (& right)[N])
^
C:\local\boost_1_74_0\boost/core/swap.hpp:50:33: error: use of undeclared identifier ‘T’
void swap_impl(T (& left)[N], T (& right)[N])
^
C:\local\boost_1_74_0\boost/core/swap.hpp:50:45: error: use of undeclared identifier ‘N’
void swap_impl(T (& left)[N], T (& right)[N])
^
C:\local\boost_1_74_0\boost/core/swap.hpp:50:48: error: expected ‘;’ after top level declarator
void swap_impl(T (& left)[N], T (& right)[N])
^
C:\local\boost_1_74_0\boost/core/swap.hpp:62:3: error: unknown type name ‘host
BOOST_GPU_ENABLED
^
C:\local\boost_1_74_0\boost/config/compiler/nvcc.hpp:23:27: note: expanded from macro ‘BOOST_GPU_ENABLED’
#define BOOST_GPU_ENABLED host device
^
In file included from ROOT_prompt_1:1:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint.hpp:25:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/util/ublas_wrapper.hpp:30:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/algebra/default_operations.hpp:24:
In file included from C:\local\boost_1_74_0\boost/array.hpp:48:
In file included from C:\local\boost_1_74_0\boost/swap.hpp:15:
C:\local\boost_1_74_0\boost/core/swap.hpp:62:20: error: expected ‘;’ at end of declaration
BOOST_GPU_ENABLED
^
C:\local\boost_1_74_0\boost/core/swap.hpp:63:52: error: use of undeclared identifier ‘T1’
typename enable_if_c< !boost_swap_impl::is_const::value && !boost_swap_impl::is_const::value >::type
^
C:\local\boost_1_74_0\boost/core/swap.hpp:63:98: error: definition or redeclaration of ‘value’ cannot name the global scope
typename enable_if_c< !boost_swap_impl::is_const::value && !boost_swap_impl::is_const::value >::type
~~^
C:\local\boost_1_74_0\boost/core/swap.hpp:63:98: error: no member named ‘value’ in the global namespace
typename enable_if_c< !boost_swap_impl::is_const::value && !boost_swap_impl::is_const::value >::type
~~^
C:\local\boost_1_74_0\boost/core/swap.hpp:63:103: error: expected ‘;’ after top level declarator
typename enable_if_c< !boost_swap_impl::is_const::value && !boost_swap_impl::is_const::value >::type
^
In file included from ROOT_prompt_1:1:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint.hpp:25:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/util/ublas_wrapper.hpp:32:
In file included from C:\local\boost_1_74_0\boost/numeric/odeint/util/is_resizeable.hpp:26:
In file included from C:\local\boost_1_74_0\boost/fusion/include/front.hpp:11:
In file included from C:\local\boost_1_74_0\boost/fusion/sequence/intrinsic/front.hpp:11:
In file included from C:\local\boost_1_74_0\boost/fusion/sequence/intrinsic_fwd.hpp:13:
In file included from C:\local\boost_1_74_0\boost/fusion/support/is_sequence.hpp:11:
C:\local\boost_1_74_0\boost/fusion/support/sequence_base.hpp:26:25: error: unknown type name ‘host
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
^
C:\local\boost_1_74_0\boost/fusion/support/config.hpp:16:34: note: expanded from macro ‘BOOST_FUSION_GPU_ENABLED’

#define BOOST_FUSION_GPU_ENABLED BOOST_GPU_ENABLED
^
C:\local\boost_1_74_0\boost/config/compiler/nvcc.hpp:23:27: note: expanded from macro ‘BOOST_GPU_ENABLED’
#define BOOST_GPU_ENABLED host device
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
Assertion failed: (DC->hasExternalVisibleStorage() || Pos != Map->end()) && “no lookup entry for decl”, file D:\xtovo\root_src.head\interpreter\llvm\src\tools\clang\lib\AST\DeclBase.cpp, line 1478

What is wrong with me? :slight_smile:

Thanks.
Regards. Valeriy

Well, I just downloaded the Windows zip file, extracted it somewhere and that was enough. What is choco install ?

Chocolatey is “advanced” npm == apt-get under windows

Windows zip file,

the whole boost? or just odeint?

The whole thing (185 Mb zip file, 651 Mb unzipped)

Somehow, when inside the ROOT interpreter, BOOST_GPU_ENABLED gets defined (as if you were compiling this code with nvcc, as cuda code).

I think the relevant section of the boost code that finally causes BOOST_GPU_ENABLED to be defined is here: config/select_compiler_config.hpp at 83fd6b3e9d3709d3efdc609a5aceb9d5851212b0 · boostorg/config · GitHub

As you see that includes nvcc.hpp if __CUDACC__ is defined. Now: @xtovo or @bellenot can you think of any reason why __CUDACC__ should end up being defined inside the ROOT interpreter on Windows? Actually, let’s verify that: @xtovo can you please try to run the following in the interpreter?

~ root -l
root [0] #ifdef __CUDACC__
root (cont'ed, cancel with .@) [1]std::cout << "argh\n";
root (cont'ed, cancel with .@) [2]#else
root (cont'ed, cancel with .@) [3]std::cout << "all ok\n";
root (cont'ed, cancel with .@) [4]#endif
all ok
root [5]

Cheers,
Enrico

P.S.
nevermind, @bellenot this is a bug in our build system…

@eguiraud right, as written in the comments, it’s a silly workaround. I’ll have to check the latest version of Visual Studio if it’s still relevant

@xtovo until that is resolved I’m afraid your options are:

  • downgrading your version of Visual Studio to a version <= 16.6
  • patching boost to never include nvcc.h
  • use Linux, or Windows Subsystem for Linux

Indeed Windows support is currently experimental, these kind of things happen from time to time, sorry about that.

And not to forget the list of open bug reports at Microsoft, and the incompatibilities between MS and Clang…

The PR is there: Disable the __CUDACC__ macro definition with latest Visual Studio by bellenot · Pull Request #8617 · root-project/root · GitHub