This commit is contained in:
guanjihuan 2024-04-02 14:29:37 +08:00
parent ca1bb0b8df
commit 7a049ccc5e
10 changed files with 52 additions and 7 deletions

View File

@ -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)

View File

@ -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

View File

@ -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): # 要执行的代码

View File

@ -1,9 +1,9 @@
# 数组分割示例
import numpy as np
import guan
cpus = 4
task_num = 4
parameter_array_all = np.arange(0, 17, 1)
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)
print(parameter_array)
print()

View File

@ -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/38912
"""
import guan
stock_symbols_60, stock_symbols_00, stock_symbols_30, stock_symbols_68, \

View File

@ -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/38912
"""
import guan
import numpy as np
import datetime

View File

@ -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/38912
"""
import guan
stock_symbols_60, stock_symbols_00, stock_symbols_30, stock_symbols_68, \
stock_symbols_8_4,stock_symbols_others = guan.stock_symbols_classification()

View File

@ -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/38912
"""
import guan
file_list_60 = guan.get_all_filenames_in_directory(directory='./2018_01_01_to_2024_03_07/stock_data_60', \
file_format=None, show_root_path=0, sort=1, include_subdirectory=1)

View File

@ -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/39020
"""
import numpy as np
from sklearn.decomposition import PCA

View File

@ -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/39020
"""
import numpy as np
from sklearn.decomposition import PCA