我正在学习如何在我们使用LSF的实验室群集中使用HPC。我尝试了一个简单的串行作业,每个作业计算文本文件中单词的频率。我编写了一个python代码,用于计算名为count_word_freq.py的单词频率,一个名为myjob.job的作业脚本如下:
python count_word_freq.py --in ~/books/1.txt --out ~/freqs/freq1.txt
python count_word_freq.py --in ~/books/2.txt --out ~/freqs/freq2.txt
python count_word_freq.py --in ~/books/3.txt --out ~/freqs/freq3.txt
python count_word_freq.py --in ~/books/4.txt --out ~/freqs/freq4.txt
python count_word_freq.py --in ~/books/5.txt --out ~/freqs/freq5.txt
和一个lsf脚本,用于将序列作业提交给selfscheduler:
#!/bin/bash
#BSUB -J test01
#BSUB -P acc_pandeg01a
#BSUB -q alloc
#BSUB -W 20
#BSUB -n 20
#BSUB -m manda
#BSUB -o %J.stdout
#BSUB -eo %J.stderr
#BSUB -L /bin/bash
module load python
module load py_packages
module load selfsched
# And run the program; output will be on stdout
mpirun selfsched < myjobs001.jobs
python代码如下:
def readBookAsFreqDict(infile):
dic = {}
with open(infile,"r") as file:
for line in file:
contents = line.split(" ")
for cont in contents:
if str.isalpha(cont):
if cont not in dic.keys():
dic[cont] = 1
else:
dic[cont] = dic[cont] + 1
return dic
import sys
import argparse
import time as T
if __name__ == "__main__":
start = T.time()
parser = argparse.ArgumentParser()
parser.add_argument('--i', type=str, help = 'input file')
parser.add_argument('--o', type=str, help = 'output file')
args = parser.parse_args()
dic = readBookAsFreqDict(args.i)
outfile = open(args.o,"w")
for key,freq in dic.iteritems():
outfile.write(key + ":" + str(freq) + "\n")
end = T.time()
print (end - start)
5个输入文本的大小几乎相同,约为3.5 MB。我的问题是,运行此串行作业的CPU时间是980秒,这比按顺序运行它更糟糕。
据我了解,selfscheduler可以自动将5个作业分配给空节点,从而可以节省运行顺序的运行时间。那是因为与找到空节点的时间相比,每个作业的执行时间太短了吗?有没有其他方法可以使它更快?
谢谢!