update
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
This code is supported by the website: https://www.guanjihuan.com
|
||||
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4536
|
||||
"""
|
||||
|
||||
from multiprocessing import Process
|
||||
import os
|
||||
import time
|
||||
@@ -14,12 +19,12 @@ def main(parameter_array, task_index):
|
||||
guan.write_one_dimensional_data(parameter_array, result_array, filename='task_index='+str(task_index))
|
||||
|
||||
if __name__ == '__main__':
|
||||
cpus = 4
|
||||
task_num = 4
|
||||
parameter_array_all = np.arange(0, 17, 1)
|
||||
start_time = time.perf_counter()
|
||||
process_array = []
|
||||
for task_index in range(cpus):
|
||||
parameter_array = guan.preprocess_for_parallel_calculations(parameter_array_all, cpus, task_index)
|
||||
for task_index in range(task_num):
|
||||
parameter_array = guan.preprocess_for_parallel_calculations(parameter_array_all, task_num, task_index)
|
||||
process_array.append(Process(target=main, args=(parameter_array, task_index)))
|
||||
for process in process_array: # 运行子进程
|
||||
process.start()
|
||||
@@ -28,7 +33,7 @@ if __name__ == '__main__':
|
||||
end_time = time.perf_counter()
|
||||
print('运行时间=', (end_time-start_time), '\n')
|
||||
f = open('result.txt', 'w')
|
||||
for task_index in range(cpus):
|
||||
for task_index in range(task_num):
|
||||
with open('task_index='+str(task_index)+'.txt', 'r') as f0:
|
||||
text = f0.read()
|
||||
f.write(text)
|
||||
|
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
This code is supported by the website: https://www.guanjihuan.com
|
||||
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4536
|
||||
"""
|
||||
|
||||
from multiprocessing import Process
|
||||
import os
|
||||
import time
|
||||
|
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
This code is supported by the website: https://www.guanjihuan.com
|
||||
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4536
|
||||
"""
|
||||
|
||||
from multiprocessing import Process, Value
|
||||
|
||||
def run_proc(name, a, num): # 要执行的代码
|
||||
|
Reference in New Issue
Block a user