[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use mpirun with C or C++ Org-babel?

From: Leo Butler
Subject: Re: How to use mpirun with C or C++ Org-babel?
Date: Fri, 8 Dec 2023 15:47:48 +0000
User-agent: Gnus/5.13 (Gnus v5.13)

On Fri, Dec 08 2023, tbanelwebmin <tbanelwebmin@free.fr> wrote:

> Caution: This message was sent from outside the University of Manitoba.
> On 23-12-08 00:10, Edgar Lux wrote:
>     Hello, I found [1][2] that it is possible to change the compiler for C 
> and C++
>     source blocks. I would like to know if there is a way to add =mpirun -np 
> 2=
>     (where 2 can be any other number) to run the resulting executable. 
> Thanks! [1] 
>     https://orgmode.org/worg//org-contrib/babel/languages/ob-doc-C.html [2] 
>     https://github.com/gheber/literate-hdf5
> I guess you want to run the executable after it has been compiled, with a 
> command
> like this one:
> mpirun -np 2 /tmp/babel-ad2pdk/C-bin-JTvjS4
> Currently it is not possible.
> There is the :cmdline specifier which adds parameters to the executable, like 
> this:
> #+begin_src C++ :cmdline AAA BBB CCC
> int main (int nargs, char** argv)
> {
>    // argv will be {
>    //   "/tmp/babel-ad2pdk/C-bin-JTvjS4",
>    //   "AAA",
>    //   "BBB",
>    //   "CCC"
>    // }
> }
> #+end_src
> Those parameters come AFTER the executable, whereas mpirun should come BEFORE 
> the
> executable.
> An extension may be written in ob-C.el, in the org-babel-C-execute function.
> The relevant line is:
>   (concat tmp-bin-file cmdline)
> If you want to contribute...

If you are wanting to run jobs with mpirun, then I will guess that they
are relatively long-running. However, ob-C.el does not support
asynchronous (background) execution, so your emacs would be tied up for
the duration. I doubt you want that.

I submitted an imperfect patch some time ago [1] that targeted your use
case: allow ob-C.el to create a named binary. Unfortunately, Ihor
dropped the issue due to lack of interest from other users.

My goal was to enable something like this to work:

#+begin_src cpp :includes <iostream> :results none :file ./hello-world
std::cout << "Hello World!\n";

#+begin_src bash :async t
mpirun -np 4 ./hello-world

As I said, the patch I wrote was not perfect, but I am happy to re-visit
the issue. The ability to create named binaries would significantly
increase the usability of ob-C for projects where you want to compile
the source once and run the binary repeatedly for potentially long
periods of time.


[1] https://list.orgmode.org/87fs81egk5.fsf@t14.reltub.ca/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]