Интересное дополнение.
Для симметрии не хватает оценки вообще без потоков.
А вообще алгоритмы рулят а не количество процессоров…
Тут правда уже некорректно измеряется.
import numpy as np
from scipy.integrate import quad,simps
from time import clock
def integrand(x):
return np.abs(np.sin(x))
t0=clock()
npoint=13
x=np.linspace(0, np.pi/2,npoint)
ans = simps(np.abs(np.sin(x)), dx=np.pi/2/(npoint-1))
t1=clock()
print "simps 1",ans,t1-t0
t0=clock()
ans, err = quad(integrand, 0, np.pi/2)
t1=clock()
print "quad",ans,t1-t0
t0=clock()
npoint=10000000
x=np.linspace(0, np.pi/2,npoint)
ans = simps(np.abs(np.sin(x)), dx=np.pi/2/(npoint-1))
t1=clock()
print "simps 0",ans,t1-t0
simps 1 1.00000163444 0.000127365258906
quad 1.0 0.000169417306416
simps 0 1.0 0.966470488785
К сожалению ваш код у меня не работает. :(
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\comp\Python33\lib\multiprocessing\forking.py", line 350, in main
prepare(preparation_data)
File "C:\comp\Python33\lib\multiprocessing\forking.py", line 457, in prepare
'__parents_main__', file, path_name, etc
File "C:\comp\Python33\lib\imp.py", line 180, in load_module
return load_source(name, filename, file)
File "C:\comp\Python33\lib\imp.py", line 119, in load_source
_LoadSourceCompatibility(name, pathname, file).load_module(name)
File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1022, in load_module
File "<frozen importlib._bootstrap>", line 1003, in load_module
File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 868, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "C:\PROJECTS\prjdocs\and\social\solution_method\simulation\cpp\bbb.py", line 39, in <module>
a=Inthread(0, math.pi/2, 10000)
File "C:\PROJECTS\prjdocs\and\social\solution_method\simulation\cpp\bbb.py", line 20, in Inthread
manager = Manager()
File "C:\comp\Python33\lib\multiprocessing\__init__.py", line 73, in Manager
m.start()
File "C:\comp\Python33\lib\multiprocessing\managers.py", line 486, in start
self._process.start()
File "C:\comp\Python33\lib\multiprocessing\process.py", line 111, in start
self._popen = Popen(self)
File "C:\comp\Python33\lib\multiprocessing\forking.py", line 216, in __init__
cmd = ' '.join('"%s"' % x for x in get_command_line())
File "C:\comp\Python33\lib\multiprocessing\forking.py", line 328, in get_command_line
is not going to be frozen to produce a Windows executable.''')
RuntimeError:
Attempt to start a new process before the current process
has finished its bootstrapping phase.
This probably means that you are on Windows and you have
forgotten to use the proper idiom in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce a Windows executable.
Traceback (most recent call last):
File "C:\PROJECTS\prjdocs\and\social\solution_method\simulation\cpp\bbb.py", line 39, in <module>
a=Inthread(0, math.pi/2, 10000)
File "C:\PROJECTS\prjdocs\and\social\solution_method\simulation\cpp\bbb.py", line 20, in Inthread
manager = Manager()
File "C:\comp\Python33\lib\multiprocessing\__init__.py", line 73, in Manager
m.start()
File "C:\comp\Python33\lib\multiprocessing\managers.py", line 490, in start
self._address = reader.recv()
File "C:\comp\Python33\lib\multiprocessing\connection.py", line 251, in recv
buf = self._recv_bytes()
File "C:\comp\Python33\lib\multiprocessing\connection.py", line 307, in _recv_bytes
[ov.event], False, INFINITE)
KeyboardInterrupt