思路
计算中需要读取几十GB的文件(文件大概有100个),顺序读取太慢,想用并行试试。6核读取时间将近缩短了5倍,效果极其满意。
python读取文件夹下所有同一类文件名name,将这些文件名写入多个文件file下,fortran循环读取file下name,依据name变量读取文件夹下所有同一类文件内容。将多个文件file记为循环变量i,采用openmp 设定线程数=i,从而并行读取文件。
服务器硬盘采用RAID 5,理论上可获得极好的读写效率。
python获取文件名并放在一些文件内
#!/usr/bin/env python3
from ase.data import atomic_numbers, atomic_names
from os import listdir
import os,sys,math
from os.path import isfile, join, exists
from natsort import ns, natsorted
import numpy as np
gbw_lst = []
for f in [ f for f in listdir(".") if isfile(join(".",f)) ]:
if f.endswith(".mos"): gbw_lst += [f] ; print('*************gbw file found!************')
number=0
mos=[]
gbw_lst=natsorted(gbw_lst,alg=ns.PATH)
'