Chapel programming language
Alright alright… having written short posts regarding first explorations of Kotlin, Mojo, Elixir, JavaScript… and now Chapel, I think it’s safe to say I like to check out what’s out there and am curious about programming languages.
I just so happened to stumble upon Chapel this week and after having explored it for just a bit I’m surprised that I didn’t know about it before.
I’m interested particularly in performance, and always felt drawn towards performant languages. But as fun as it can be to think about L1, L2 cache sizes and to program in a data-oriented manner, it doesn’t mean much if your language of choice doesn’t lend itself to parallelization. Hardware, especially after the dawn of multi-core CPUs and now even more so given powerful GPUs, isn’t your PDP-11 C was invented for. (one could even argue assembly itself doesn’t map well to multi-core CPUs to begin with anymore…)
So yes, you can end up using OpenMP, writing crafty, verbose, difficult to debug C (without namespaces, without the proper concept of a package/module, dealing with the C build system…) or use Chapel, which seems to get you 95% of the way there in 10% of the effort.
So, apparently, being interested in high performance computing and programming languages, I didn’t know about a:
- high-performance compiled language
- w/ nice syntax
- which can interface w/ C
- isn’t exactly new (2009)
- is open-source and permissively licensed (Apache 2)
- is openly developed on GitHub
- and (experience thus far) seems to have good documentation
- and is used and developed by the company w/ 7 systems in the overall Top 10 of supercomputers (as of writing)
And it’s not your sciency community-niche 90s website, tarball download, no community outreach project either. Some papers on it, good conference talks, official YouTube, Discord, Discourse Forum, Twitter, …
config const cC: int = 1;
config param cP: bool = false;
config type cT = complex;
// foreach
var A: [0..5] real;
foreach a in A do {
a = 1.1;
a *= 2;
}
writeln("A after foreach: ", A); // 2.2 2.2 2.2 2.2 2.2 2.2
// forall
write("forall (any order possible): ");
forall i in 0..<10 do {
write(" ", i);
}
writeln();
From just this short code example:
configparametersconstruntime const (can be set at runtime)paramcompile const (can be set when compiling)type(also compile time const)
So this means:
- executing via
./exe --cC=2we can change its value when running - compiling w/
chpl src.chpl -s cP=true -s cT=imagwe changed both for compilation
Also:
foreachis hardware-parallel (vectorized), attempting SIMD/SIMTforallis software-parallel (uses threads akin to machine core count)var A: [0..5] real;- nice array syntax
- use 0 or 1-index
[0..5],[1..5]whatever lends itself best to an algorithm- or 1-based for interfacing w/ or translating from Fortran for example
- default-initialized to type’s 0 value by default (
0.0for areal)
… the code looks nice, is succinct, performant… and not even showcased: you can very simply run computations on many compute nodes, even GPUs without CUDA… so… isn’t this even more what Mojo wants to be, but only already proven and working? And not being pythonic and not being built on top of a duck-typed scripting language is a plus (albeit Python’s infra, set of libraries and momentum are always difficult to fully ignore…)
Further resources:
- Hello World variants
- (showcases parallelism and distributed programs)
- Chapel presentation