Skip to content

Commit 118a36f

Browse files
committed
Parallel: dependencies
1 parent 4728d12 commit 118a36f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

docs/day4/parallel.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,24 @@ in Python rather than learning to write those codes.
434434
Optional flags for ``srun`` for writing output and error files are ``-o output_%j.out -e error_%j.err`` instead
435435
of writing on the terminal screen.
436436

437+
**Data dependencied**
438+
439+
In general, one cannot parallelize an serial algorithm; let's take the case of:
440+
441+
442+
.. code-block:: python
443+
444+
a[0] = 0
445+
for i in range(1, N):
446+
a[i] = a[i-1] + i
447+
448+
Here, the iteration *i* depends on the previous iteration *i-1*. One needs to transform this algorithm:
449+
450+
.. code-block:: python
451+
452+
for i in range(N):
453+
a[i] = 0.5 * i * (i + 1)
454+
437455
438456
439457
2D integration

0 commit comments

Comments
 (0)