Hello, world
As our first example of coNCePTuaL
programming, here's how to write a coNCePTuaL program in which every task
(meaning a process, thread, or some other unit of program control)
outputs the string
Hello, world!
to the standard output device.
The following is a complete Hello, world
program written in
coNCePTuaL:
coNCePTuaL is intended for writing
parallel programs, implying that a typical coNCePTuaL program comprises multiple tasks that
execute concurrently. Each task is identified by a task
number, a unique integer ranging from zero to one less than the
number of tasks in the program. To make our Hello, world
program more interesting, let's have each task output its task
number:
In the above, each task stores its task number in the variable
mytask
and subsequently outputs mytask
.
The coNCePTuaL compiler is unique in
that is provides multiple code generators, called backends.
Each backend lets the user specify a target language and communication
library for which to generate code. Let's compile our Hello,
world
program into C and use Unix-domain datagrams for
communication:
The compiler converted helloworld.ncptl to a temporary C file (tmp-dRzoa.c), passed that to the C compiler, produced an executable called helloworld, and deleted the temporary C file. (The --keep-ints compiler option tells the compiler to keep intermediate files. If you're interested, you can look at the generated helloworld.c file, but be forewarned: it's not pretty.)
Let's specify that we want our parallel program to run with eight tasks:
All tasks run concurrently. Hence, the lines of output appear in no particular order.
How did we know to use --tasks? Easy; all coNCePTuaL programs automatically provide support for a --help option:
$ ./helloworld --help
Usage: helloworld [OPTION...]
-C, --comment=<string> Additional commentary to write to the log file,
@FILE to import commentary from FILE, or
!COMMAND to import commentary from COMMAND (may
be specified repeatedly)
-L, --logfile=<string> Log-file template [default: "helloworld-%p.log"]
-N, --no-trap=<string> List of signals which should not be trapped
[default: ""]
-T, --tasks=<number> Number of tasks to use [default: 1]
-W, --watchdog=<number> Number of minutes after which to kill the job
(-1=never) [default: -1]
Help options:
-?, --help Show this help message
--usage Display brief usage message
Not bad for one line of coNCePTuaL code, eh?
The most common use of coNCePTuaL is to produce parallel programs using MPI as the communication layer. Let's recompile helloworld.ncptl using MPI instead of Unix-domain datagrams:
All we had to do was recompile with a different value for --backend to completely replace all socket calls with MPI calls. (If you like reading ugly code, you may want to compare and contrast the MPI version of helloworld.c file to the datagram version of helloworld.c.)
Let's review what we learned in this exercise: