2024-heraklion-parallel-python/exercises/exerciseB
2024-08-30 12:50:14 +03:00
..
numerical_integration.py renaming exercises 2024-08-29 18:23:32 +03:00
numerical_integration_solution.py renaming exercises 2024-08-29 18:23:32 +03:00
README.md adjust list formatting 2024-08-30 12:50:14 +03:00

Exercise B: multiprocessing and map

Objective: introduce map and Pool.map.

In the numerical_integration.py file, we give Python code that calculates the integral of a function in two different ways: numerically and analytically.

The given functions are integrate (numerical integration), f (the function to integrate), and F (the analytical integral).

We want to check the precision of the numerical integration as a function of the number of steps in the domain. To do this, we calculate and print the relative differences between the analytic result and the numerical result for different values of the number of steps.

TASKS:

  1. Read numerical_integration.py and familiarize yourselves with the code.
  2. Update the main function so that it calculates the numerical error without any parallelization. You can use a for loop or map.
  3. Note the execution time for this serial implementation.
  4. Implement the parallel version using multiprocessing.Pool.
  5. Compare the timing for the parallel version with the serial time. What speed-up did you get?

BONUS TASKS (very optional):

  1. Implement a parallel version with threads (using multiprocessing.pool.ThreadPool).
  2. Time this version, and hypothetize about the result.