Orca: print process ids

30 May 2022

In Orca, one process acts as a master process (first process with id 0) driving the execution of the computation defined in the kernel code, while the worker processes wait for the commands from the master process and perform the computation. Orca utilizes MPI routines for communication between processes. In this post, I implemented a simple parallel application using Orca’s rpc-make function to print the numbers of all worker processes.

Orca APIs are categorized into three classes: utility APIs such as rpc-worker-process-id and rpc-worker-process-size; bootstrapping APIs such as rpc-start, and compute APIs (rpc-make, rpc-apply-bcast, rpc-apply-scatter etc.) performing computation on a given expression in parallel. To give information on some of the basic Orca APIs:

(rpc-start) ⇒ void
Bootstrap the execution environment. rpc-start is required to be called by all processes to bootstrap the execution environment. When a worker process calls rpc-start, the process enters a loop and the flow of the execution never goes beyond the rpc-start. On the other hand, when rpc-start is called in the context of the master process, the execution continues. Note that in Orca the process with id 0 acts as master process but also joins the computation like a worker process.
(rpc-finalize) ⇒ void
Terminate the execution environment. The function rpc-finalize is called by the master process to terminate the execution environment. When the function is invoked, a finalize message is sent to all worker processes that instruct them to terminate the loop, and then worker processes exit.
(rpc-worker-process-id) ⇒ integer
Determines every worker process uniquely where process numbering begins with 0 and goes up to size − 1.
(rpc-worker-process-size) ⇒ integer
Determines total number of worker processes (size) joining the computation.
(rpc-make <symbolic expression>) ⇒ list
Executes the given symbolic expression collectively where the expression is given in a “quoted” form. The function broadcasts the given expression to all worker processes in which every worker process executes the expression and sends back the result of the expression to the master process. rpc-make returns a list of values where each i-th element in the list is the result of the computation from the i-th worker.

In the example, the kernel code (rpc-print-process-ids.scm) prints the numbers of all worker processes. The symbolic expression (process-id-message) given to the rpc-make function as an argument is broadcasted to all worker processes where the function process-id-message is invoked by all worker processes. Because rpc-start blocks the execution of worker processes, the function process-id-message must be defined before the rpc-start call in the kernel code. Each worker process constructs a string message containing the process id using Orca’s rpc-worker-process-id function.

(use-modules (orca))

(define (process-id-message) (format #f "process ~a" (rpc-worker-process-id)))
(format #t "I'm master process. Received ~s ~%" (rpc-make '(process-id-message)))

Start the MPI application with 4 processes via:

mpirun -n 4 ./rpc-print-process-ids.scm


I'm master process. Received ("process 0" "process 1" "process 2" "process 3")

For more Orca examples, please navigate to here.

Copyright © 2020, 2021, 2022 Ahmet Artu Yıldırım.
E-Mail: <ahmet at artulab period com> | GPG Key
Verbatim copying and redistribution of any material in this page is permitted under the Creative Commons Noderivs license version 3.0 or later.