Chapel

From Alliance Doc
Revision as of 04:21, 10 December 2021 by Razoumov (talk | contribs)
Jump to navigation Jump to search
Other languages:

Chapel[edit]

Chapel is a general-purpose, compiled, high-level parallel programming language with built-in abstractions for shared- and distributed-memory parallelism. There are two styles of parallel programming in Chapel: (1) task parallelism, where parallelism is driven by programmer-specified tasks, and (2) data parallelism, where parallelism is driven by applying the same computation on subsets of data elements, which may be in the shared memory of a single node, or distributed over multiple nodes.

These high-level abstractions make Chapel ideal for learning parallel programming for a novice HPC user. Chapel is incredibly intuitive, striving to merge the ease-of-use of Python and the performance of traditional compiled languages such as C and Fortran. Parallel blocks that typically take tens of lines of MPI code can be expressed in only a few lines of Chapel code. Chapel is open source and can run on any Unix-like operating system, with hardware support from laptops to large HPC systems.

Chapel has a relatively small user base, so many libraries that exist for C, C++, Fortran have not yet been implemented in Chapel. Hopefully, that will change in coming years, if Chapel adoption continues to gain momentum in the HPC community.

For more information, please watch our three-part Chapel webinar.

Single-locale Chapel[edit]

Single-locale (single node; shared-memory only) Chapel on Compute Canada's general-purpose clusters is provided by the module chapel-multicore. You can use salloc to test Chapel codes either in serial:

[name@server ~]$ module load gcc/9.3.0 chapel-multicore/1.25.0
[name@server ~]$ salloc --time=0:30:0 --ntasks=1 --mem-per-cpu=3600 --account=def-someprof
[name@server ~]$ chpl test.chpl -o test
[name@server ~]$ ./test

or on multiple cores on the same node:

[name@server ~]$ module load gcc/9.3.0 chapel-multicore/1.25.0
[name@server ~]$ salloc --time=0:30:0 --ntasks=1 --cpus-per-task=3 --mem-per-cpu=3600 --account=def-someprof
[name@server ~]$ chpl test.chpl -o test
[name@server ~]$ ./test

For production jobs, please write a job submission script and submit it with sbatch.

Multi-locale Chapel[edit]

Multi-locale (multiple nodes; hybrid shared- and distributed-memory) Chapel is provided by chapel-ofi (for the OmniPath interconnect on Cedar) and chapel-ucx (for the InfiniBand interconnect on Graham, Béluga, Narval) modules.

Consider the following Chapel code printing basic information about the nodes available inside your job:

File : probeLocales.chpl

use Memory.Diagnostics;
for loc in Locales do
  on loc {
    writeln("locale #", here.id, "...");
    writeln("  ...is named: ", here.name);
    writeln("  ...has ", here.numPUs(), " processor cores");
    writeln("  ...has ", here.physicalMemory(unit=MemUnits.GB, retType=real), " GB of memory");
    writeln("  ...has ", here.maxTaskPar, " maximum parallelism");
  }


To run this code on Cedar, you need to load the chapel-ofi module:

[name@server ~]$ module load gcc/9.3.0 chapel-ofi/1.25.0
[name@server ~]$ salloc --time=0:30:0 --nodes=4 --cpus-per-task=3 --mem-per-cpu=3500 --account=def-someprof


Once the interactive job starts, you can compile and run your code from the prompt on the first allocated compute node:

[name@server ~]$ chpl probeLocales.chpl -o probeLocales
[name@server ~]$ ./probeLocales -nl 4

To run the same code on InfiniBand clusters (Graham, Béluga, Narval), use the chapel-ucx module.

For production jobs, please write a Slurm submission script and submit your job with sbatch instead.