1.. _smp_pi:
2
3SMP Pi
4###########
5
6Overview
7********
8This sample application calculates Pi independently in many threads, and
9demonstrates the benefit of multiple execution units (CPU cores)
10when compute-intensive tasks can be run in parallel, with
11no cross-dependencies or shared resources.
12
13By changing the value of CONFIG_MP_MAX_NUM_CPUS on SMP systems, you
14can see that using more cores takes almost linearly less time
15to complete the computational task.
16
17You can also edit the sample source code to change the
18number of digits calculated (``DIGITS_NUM``), and the
19number of threads to use (``THREADS_NUM``).
20
21Building and Running
22********************
23
24This project outputs Pi values calculated by each thread and in the end total time
25required for all the calculation to be done. It can be built and executed
26on Synopsys ARC HSDK board as follows:
27
28.. zephyr-app-commands::
29   :zephyr-app: samples/arch/smp/pi
30   :host-os: unix
31   :board: qemu_x86_64
32   :goals: run
33   :compact:
34
35Sample Output
36=============
37
38.. code-block:: console
39
40    Calculate first 240 digits of Pi independently by 16 threads.
41    Pi value calculated by thread #0: 3141592653589793238462643383279502884197...
42    Pi value calculated by thread #1: 3141592653589793238462643383279502884197...
43    ...
44    Pi value calculated by thread #14: 314159265358979323846264338327950288419...
45    Pi value calculated by thread #15: 314159265358979323846264338327950288419...
46    All 16 threads executed by 4 cores in 28 msec
47