Multicore ARF Computation#

In this example we show how multiprocessing can be used to improving computation speed for ARF plots.

For computationally expensive models, i.e. models that include numerical integration the OSAFT library provides the option for computing the ARF using multiprocessing. If a solution class is added to an ARFPlot instance using add_solutions the parameter multicore can be set to True. Now the computation of the ARF for each point of the plot will be computed in a new process that will run in parallel.

The models used in the example below should probably not be used with the multicore option, since they are simple and evaluate very fast. For simple models multiprocessing will not lead to faster evaluation.

Important

In order for multiprocessing to work you need to run your code in your main file inside the if __name__ == '__main__': clause as shown below. Check the multiprocessing documentation for more information.

32 import numpy as np
33 from matplotlib import pyplot as plt
34
35 import osaft
36
37
38 def main():
39
40     king = osaft.king1934.ARF(
41         f=1e6,
42         R_0=1e-6,
43         rho_s=1020,
44         rho_f=997,
45         c_f=1498,
46         p_0=1e5,
47         wave_type=osaft.WaveType.STANDING,
48         position=osaft.pi / 4,
49     )
50
51     yosioka = osaft.yosioka1955.ARF(
52         f=1e6,
53         R_0=1e-6,
54         rho_s=1020,
55         c_s=2350,
56         rho_f=997,
57         c_f=1498,
58         p_0=1e5,
59         wave_type=osaft.WaveType.STANDING,
60         position=osaft.pi / 4,
61     )
62
63     gorkov = osaft.gorkov1962.ARF(
64         f=1e6,
65         R_0=1e-6,
66         rho_s=1020,
67         c_s=2350,
68         rho_f=997,
69         c_f=1498,
70         p_0=1e5,
71         wave_type=osaft.WaveType.STANDING,
72         position=osaft.pi / 4,
73     )
74
75     plot = osaft.ARFPlot("R_0", np.linspace(1e-6, 20e-6))
76
77     # Solutions added using multiprocessing
78     plot.add_solutions(king, yosioka, multicore=True)
79
80     # Solutions added without multiprocessing
81     plot.add_solutions(gorkov)
82
83     plot.plot_solutions()
84
85     plt.show()
86
87
88 if __name__ == "__main__":
89     main()
example multicore
/home/docs/checkouts/readthedocs.org/user_builds/osaft/checkouts/stable/osaft/plotting/datacontainers/arf_datacontainer.py:56: AssumptionWarning: Theory might not be valid anymore!
  self._arf = self._compute_arf_single_process(attr_name, values)

Total running time of the script: ( 0 minutes 0.610 seconds)

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery