Skip to content

Commit

Permalink
Update Tutorials “introduction-to-cilk-programming”
Browse files Browse the repository at this point in the history
  • Loading branch information
behoppe committed Aug 2, 2022
1 parent bf68a95 commit e0ebf3a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/doc/tutorials/introduction-to-cilk-programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tags:
- spawn
---
## Task-parallel programming

{% defn "parallel algorithms", "Parallel programming" %} involves writing instructions that can be executed on different processors simultaneously. Compared to serial programming, parallel programming offers opportunities to reduce the resources consumed (e.g., time, storage, energy, etc.), but taking advantage of these opportunities can be exceedingly complicated and error-prone — too much for developers to manage on their own.

OpenCilk is a {% defn "task-parallel-platforms-programming-and-algorithms", "task-parallel platform" %}: a layer of software that coordinates, schedules, and manages the multiple processors of a parallel program. OpenCilk automatically load-balances the tasks of the different processors and achieves performance that is provably close to optimal.
Expand All @@ -20,8 +21,8 @@ Using the OpenCilk platform, a developer writes code in Cilk, which extends C an
and cover parallel loops in a later tutorial.

{% defn "Spawning" %} allows a function to be “forked,” or executed like a function call, except that the caller can continue to execute while the spawned function computes its result. For example, consider the fragment of C below.
Spawning occurs in line 6, where the keyword `cilk_spawn` precedes the call to function `p_fib`.
With a spawn, the instance that executes the spawn—the {% defn "parent" %}—may continue to execute in parallel with the spawned function—its {% defn "child" %}—instead of waiting for the child to finish, as would happen in a serial execution.
Spawning occurs in line 7, where the keyword `cilk_spawn` precedes the call to function `p_fib`.
With a spawn, the process (or function) that executes the spawn—the {% defn "parent" %}—may continue to execute in parallel with the spawned function—its {% defn "child" %}—instead of waiting for the child to finish, as would happen in a serial execution.

```c#
int p_fib(int n)
Expand Down Expand Up @@ -50,7 +51,7 @@ For example, the picture below depicts a basic multicore architecture where each
The keyword `cilk_scope` complements `cilk_spawn` by defining a boundary that limits the extent to which tasks may run in parallel.
Whenever the program execution leaves a block of code delimited by `cilk_scope{...}` , it must wait as necessary for all spawned functions within the block to finish before proceeding.

If you remove `cilk_spawn` and `cilk_scope` from this example program, the result is a traditional serial program.
If you remove `cilk_spawn` and `cilk_scope` from this example program, the result is a traditional serial program, which we call \`fib\`.

```c#
int fib(int n)
Expand All @@ -66,7 +67,7 @@ int fib(int n)
```

Function `fib` is the {% defn "serial projection" %} of `p_fib`,
which means it computes exactly the same result but without any tasks running simultaneously.
which means it computes exactly the same result but without running any tasks simultaneously.
So why bother with parallelism?
Because of the differences in *how* `fib` and `p_fib` compute their (identical) results.
For many computations, allowing tasks to run in parallel significantly reduces the resources required (e.g., time, storage, energy).
Expand Down

0 comments on commit e0ebf3a

Please sign in to comment.