Introduction to Chapel


  • “Chapel is a compiled language - any programs we make must be compiled with chpl.”
  • “The --fast flag instructs the Chapel compiler to optimise our code.”
  • “The -o flag tells the compiler what to name our output (otherwise it gets named after the source file)”

Basic syntax and variables


  • “A comment is preceded with // or surrounded by /* and*/`”
  • “All variables in Chapel have a type, whether assigned explicitly by the user, or chosen by the Chapel compiler based on its value.”
  • “Reassigning a new value to a const variable will produce an error during compilation. If you want to assign a new value to a variable, declare that variable with the var keyword.”

Ranges and arrays


  • “A range is a sequence of integers.”
  • “An array holds a non-negative number of values of the same type.”
  • “Chapel arrays can start at any index, not just 0 or 1.”
  • “You can index arrays with the [] brackets.”

Conditional statements


  • “Use if <condition> {instructions A} else {instructions B} syntax to execute one set of instructions if the condition is satisfied, and the other set of instructions if the condition is not satisfied.”
  • This syntax can be simplified to if <condition> {instructions} if we only want to execute the instructions within the curly brackets if the condition is satisfied.
  • “Use while <condition> {instructions} to repeatedly execute the instructions within the curly brackets while the condition is satisfied. The instructions will be executed over and over again until the condition does not hold anymore.”

Getting started with loops


  • “You can organize loops with for and while statements. Use a for loop to run over every element of the iterand, e.g. for i in 1..rows { ...} will run over all integers from 1 to rows. Use a while statement to repeatedly execute a code block until the condition does not hold anymore, e.g. while (c < niter && delta >= tolerance) {...} will repeatedly execute the commands in curly braces until one of the two conditions turns false.”

Procedures


  • “Functions in Chapel are called procedures.”
  • “Procedures can take a varying number of parameters.”
  • “Optionally, you can specify input parameter types and the return variable type.”
  • “Procedures can have default parameter values.”
  • “Procedures can be recursive. Recursive procedures require specifying the return variable type.”

Using command-line arguments


  • “Config variables accept values from the command line at runtime, without you having to recompile the code.”

Measuring code performance


  • “To measure performance, instrument your Chapel code using a stopwatch from the Time module.”

Intro to parallel computing


  • “Concurrency and locality are orthogonal concepts in Chapel: where the tasks are running may not be indicative of when they run, and you can control both in Chapel.”
  • “Problems with a lot of communication between tasks, or so called fine-grained parallel problems, are typically more difficult to parallelize. As we will see later in these lessons, Chapel simplifies writing fine-grained parallel codes by hiding a lot of communication complexity under the hood.”

Fire-and-forget tasks


  • “Use begin or cobegin or coforall to spawn new tasks.”
  • “You can run more than one task per core, as the number of cores on a node is limited.”

Synchronising tasks


  • “You can explicitly synchronise tasks with sync statement.”
  • “You can also use sync and atomic variables to synchronise tasks.”

Task parallelism with Chapel


  • “To parallelize the diffusion solver with tasks, you divide the 2D domain into blocks and assign each block to a task.”
  • “To get the maximum performance, you need to launch the parallel tasks only once, and run the temporal loop of the simulation with the same set of tasks, resuming the main task only to print the final results.”
  • “Parallelizing with tasks is more laborious than parallelizing with data (covered in the next section).”

Running code on multiple machinesIntro to multi-locale code


  • “Locale in Chapel is a shared-memory node on a cluster.”
  • “We can cycle in serial or parallel through all locales.”

Domains and data parallelismDomains and single-locale data parallelismI/O


  • “Domains are multi-dimensional sets of integer indices.”
  • “A domain can be defined on a single locale or distributed across many locales.”
  • “There are many predefined distribution method: block, cyclic, etc.”
  • “Arrays are defined on top of domains and inherit their distribution model.”