1

I want to run C++ simulations from a jupyter notebook. The program needs three values in input, i.e. 10, 0.2 and 0.6.

This what I am doing now and it works fine:

## Compile
! mpicxx -o main main.cpp Node.cpp Agent.cpp -std=gnu++11
## Run
! mpirun -np 1 ./main 10 0.2 0.6

But if try to declare those values before, it does not recognizes them.

a = 10
b = 0.2
c = 0.6
! mpirun -np 1 ./main a b c
baduker
  • 19,152
  • 9
  • 33
  • 56
emax
  • 6,965
  • 19
  • 74
  • 141
  • @YaserM yes I did – emax Mar 29 '19 at 11:56
  • Possible duplicate of [Passing IPython variables as arguments to bash commands](https://stackoverflow.com/questions/35497069/passing-ipython-variables-as-arguments-to-bash-commands) – paradox Mar 29 '19 at 12:43

3 Answers3

2

you need to type it like this

a = 10
b = 0.2
c = 0.6
! mpirun -np 1 ./main {a} {b} {c}
2

It looks like (from this document) you can wrap your Python variables in curly braces or else prefix them with the $ to get the to expand for the shell. E.g., ! mpirun -np 1 ./main {a} {b} {c}

Wolf
  • 4,254
  • 1
  • 21
  • 30
1
! mpirun -np 1 ./main {a} {b} {c}

! mpirun -np 1 ./main $a $b $c
paradox
  • 602
  • 6
  • 13