Learn Chapel - 10 Code Examples & CST Typing Practice Test
Chapel is a parallel programming language designed for high-performance computing (HPC). Developed by Cray Inc., it provides productivity features for writing scalable and portable parallel programs, combining high-level abstractions with fine-grained control over concurrency and data distribution.
Learn CHAPEL with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
Chapel Counter and Theme Toggle
var count: int = 0;
var isDark: bool = false;
proc updateUI() {
writeln("Counter: ", count);
writeln("Theme: ", if isDark then "Dark" else "Light");
}
proc increment() {
count += 1;
updateUI();
}
proc decrement() {
count -= 1;
updateUI();
}
proc reset() {
count = 0;
updateUI();
}
proc toggleTheme() {
isDark = !isDark;
updateUI();
}
// Simulate actions
updateUI();
increment();
increment();
toggleTheme();
decrement();
reset();
Demonstrates a simple counter with theme toggling using Chapel variables, procedures, and I/O.
Chapel Fibonacci Sequence
var a: int = 0;
var b: int = 1;
writeln(a);
writeln(b);
for i in 1..8 {
var c = a + b;
writeln(c);
a = b;
b = c;
}
Generates first 10 Fibonacci numbers using an iterative approach.
Chapel Factorial Calculator
proc factorial(n: int): int {
if n == 0 then return 1;
return n * factorial(n-1);
}
writeln(factorial(5));
Calculates factorial of a number using recursion.
Chapel Prime Checker
proc isPrime(n: int): bool {
if n < 2 then return false;
for i in 2..n-1 {
if n % i == 0 then return false;
}
return true;
}
writeln(if isPrime(13) then "Prime" else "Not Prime");
Checks if a number is prime.
Chapel Sum of Array
var nums = [1,2,3,4,5];
var sum = 0;
for n in nums do sum += n;
writeln(sum);
Calculates sum of an array of numbers.
Chapel Reverse String
var s = "HELLO";
var r = s.reversed();
writeln(r);
Reverses a string.
Chapel Multiplication Table
var n = 5;
for i in 1..10 do writeln(n, " x ", i, " = ", n*i);
Prints multiplication table of a number.
Chapel Celsius to Fahrenheit
var c: real = 25.0;
var f = (c * 9.0/5.0) + 32.0;
writeln(f);
Converts Celsius to Fahrenheit.
Chapel Simple Alarm Simulation
var temp = 80;
var thresh = 75;
writeln(if temp > thresh then "Alarm: Temperature Too High!" else "Temperature Normal");
Simulates an alarm if a threshold is exceeded.
Chapel Random Walk Simulation
var steps = 10;
var pos = 0;
for i in 1..steps {
if random(0,1) < 0.5 then pos += 1 else pos -= 1;
writeln(pos);
}
Simulates a 1D random walk.
Frequently Asked Questions about Chapel
What is Chapel?
Chapel is a parallel programming language designed for high-performance computing (HPC). Developed by Cray Inc., it provides productivity features for writing scalable and portable parallel programs, combining high-level abstractions with fine-grained control over concurrency and data distribution.
What are the primary use cases for Chapel?
High-performance computing (HPC) applications. Scientific simulations and modeling. Data-intensive parallel processing. Algorithm prototyping for supercomputers. Education in parallel and distributed programming
What are the strengths of Chapel?
Simplifies parallel programming for HPC. Portable across multiple architectures. Supports both task and data parallelism. Readable syntax compared to MPI/OpenMP. Strong abstraction for arrays and distributed data
What are the limitations of Chapel?
Smaller user community. Primarily used in HPC environments. Less support for general-purpose applications. Requires understanding of parallel and distributed computing. Limited third-party libraries compared to mainstream languages
How can I practice Chapel typing speed?
CodeSpeedTest offers 10+ real Chapel code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.