Skip to content
Snippets Groups Projects
Commit 4076693e authored by Mads R. B. Kristensen's avatar Mads R. B. Kristensen
Browse files

Added training materials for the Chapel Programming Language

parents
Branches
1 merge request!1Chapel training material
Chapel
======
Compilation instructions
------------------------
There are no specific requirements for building examples,
just standard make, working MPI environment (for MPI examples) and
OpenMP enabled C or Fortran compiler (for OpenMP examples).
Move to proper subfolder (C or Fortran) and modify the top of the **Makefile**
according to your environment (proper compiler commands and compiler flags).
All examples can be built with simple **make**, **make mpi** builds the MPI
examples and **make omp** OpenMP examples.
# Makefile that builds each src/*.chpl file into a binary in bin/*
CC=chpl
CFLAGS=-g
LDFLAGS=
SRC=$(wildcard src/*.chpl)
PROGRAM=$(addprefix bin/, $(subst .chpl,, $(subst src/,,$(SRC))))
all: mkdir $(PROGRAM)
bin/% : src/%.chpl
$(CC) $(CFLAGS) -o $@ $<
.PHONY: clean mkdir
mkdir:
mkdir -p bin
clean:
rm -R bin
use BlockDist;
config const n = 8;//Size of the domain squired
config const epsilon = 1.0e-10;//Stop condition in amount of change
config var iterations = 1000;//Stop condition in number of iterations
//A n+2 by n+2 domain.
const Grid = {0..n+1, 0..n+1} dmapped Block({1..n, 1..n});
//A n by n domain that represents the interior of 'Grid'
const Interior = {1..n, 1..n};
var A, T : [Grid] real;//Zero initialized as default
A[..,0] = -273.15; //Left column
A[..,n+1] = -273.15; //Right column
A[n+1,..] = -273.15; //Bottom row
A[0,..] = 40.0; //Top row
do{
//Since all iterations are independent, we can use 'forall', which allows
//the Chapel runtime system to calculate the iterations in parallel
forall (i,j) in Interior do//Iterate over all non-border cells
{
//Assign each cell in 'T' the mean of its neighboring cells in 'A'
T[i,j] = (A[i,j] + A[i-1,j] + A[i+1,j] + A[i,j-1] + A[i,j+1]) / 5;
}
//Delta is the total amount of change done in this iteration
const delta = + reduce abs(A[Interior] - T[Interior]);
//Copy back the non-border cells
A[Interior] = T[Interior];
//When 'delta' is smaller than 'epsilon' the calculation has converged
iterations -= 1;
} while (delta > epsilon && iterations > 0);
config const n = 8;//Size of the domain squired
config const epsilon = 1.0e-10;//Stop condition in amount of change
config var iterations = 1000;//Stop condition in number of iterations
//A n+2 by n+2 domain.
const Grid = {0..n+1, 0..n+1};
//A n by n domain that represents the interior of 'Grid'
const Interior = {1..n, 1..n};
var A, T : [Grid] real;//Zero initialized as default
A[..,0] = -273.15; //Left column
A[..,n+1] = -273.15; //Right column
A[n+1,..] = -273.15; //Bottom row
A[0,..] = 40.0; //Top row
do{
//Since all iterations are independent, we can use 'forall', which allows
//the Chapel runtime system to calculate the iterations in parallel
forall (i,j) in Interior do//Iterate over all non-border cells
{
//Assign each cell in 'T' the mean of its neighboring cells in 'A'
T[i,j] = (A[i,j] + A[i-1,j] + A[i+1,j] + A[i,j-1] + A[i,j+1]) / 5;
}
//Delta is the total amount of change done in this iteration
const delta = + reduce abs(A[Interior] - T[Interior]);
//Copy back the non-border cells
A[Interior] = T[Interior];
//When 'delta' is smaller than 'epsilon' the calculation has converged
iterations -= 1;
} while (delta > epsilon && iterations > 0);
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment