From 6ad2564d337aba5528c2886e7ad254faa9cb0082 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Tue, 21 Feb 2023 23:47:19 +0800 Subject: [PATCH] update --- .../2023.02.21_parapell_python_manually/a.py | 8 +++++ .../2023.02.21_parapell_python_manually/a.sh | 7 ++++ .../parallel.py | 35 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 language_learning/2023.02.21_parapell_python_manually/a.py create mode 100644 language_learning/2023.02.21_parapell_python_manually/a.sh create mode 100644 language_learning/2023.02.21_parapell_python_manually/parallel.py diff --git a/language_learning/2023.02.21_parapell_python_manually/a.py b/language_learning/2023.02.21_parapell_python_manually/a.py new file mode 100644 index 0000000..ccf38af --- /dev/null +++ b/language_learning/2023.02.21_parapell_python_manually/a.py @@ -0,0 +1,8 @@ +import numpy as np + +def run(parameter_array): + for parameter in parameter_array: + print('hello world'+' '+str(parameter)) + +parameter_array_labeled_for_replacement = [] +run(parameter_array_labeled_for_replacement) \ No newline at end of file diff --git a/language_learning/2023.02.21_parapell_python_manually/a.sh b/language_learning/2023.02.21_parapell_python_manually/a.sh new file mode 100644 index 0000000..f3d2634 --- /dev/null +++ b/language_learning/2023.02.21_parapell_python_manually/a.sh @@ -0,0 +1,7 @@ +#!/bin/sh +#PBS -N task +#PBS -l nodes=1:ppn=1 +#PBS -q bigmem +cd $PBS_O_WORKDIR +export OMP_NUM_THREADS=1 +python a.py diff --git a/language_learning/2023.02.21_parapell_python_manually/parallel.py b/language_learning/2023.02.21_parapell_python_manually/parallel.py new file mode 100644 index 0000000..c294771 --- /dev/null +++ b/language_learning/2023.02.21_parapell_python_manually/parallel.py @@ -0,0 +1,35 @@ +""" +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/29200 +""" + +import os + +parameter_str_array = ['np.arange(1, 11, 1)', 'np.arange(11, 21, 1)'] +index = 0 + +for parameter_str in parameter_str_array: + index += 1 + + # 以下处理代码文件【说明:linux系统下复制用cp,windows系统下复制用copy】 + os.system('cp a.py a'+str(index)+'.py') # 复制python代码文件 + with open('a'+str(index)+'.py', 'r') as f: # 读取 + content = f.read() + old_str = 'parameter_array_labeled_for_replacement = []' + new_str = 'parameter_array_labeled_for_replacement = ' + parameter_str + content = content.replace(old_str, new_str) + with open('a'+str(index)+'.py', 'w') as f: # 写入 + f.write(content) + + # 以下处理任务上传文件 + os.system('cp a.sh a'+str(index)+'.sh') # 复制任务调度系统的sh上传文件 + with open('a'+str(index)+'.sh', 'r') as f: # 读取 + content = f.read() + old_str = 'python a.py' + new_str = 'python a'+str(index)+'.py' + content = content.replace(old_str, new_str) + with open('a'+str(index)+'.sh', 'w') as f: # 写入 + f.write(content) + + # 提交任务 + os.system('qsub a'+str(index)+'.sh') # 提交任务 \ No newline at end of file