こんにちは、私はPythonでプログラミングを始めたばかりで、subprocess.Popenを使用して、「make」を使用してコンパイルしたプログラムの複数のインスタンスを実行しようとしています。しかし、「make」を行う前に、テキスト処理を行い、「make」が使用する一連のファイルを生成する必要があります。ここで、生成された異なるファイルで同じプログラムを同時に実行し、プログラムの出力のすべてのインスタンスの出力を同じファイルに書き込みたいと思います。インスタンスの数によっては、その数のテキスト ファイルも生成する必要があります。本質的に、最初の for ループの下ですべての操作を同時に実行したいと考えています。提供されるヘルプは大歓迎です:)。
for mC in range(monteCarlo):
print "Simulation Number",str(mC+1),"of",str(monteCarlo)
L = numpy.zeros((1,4),float)
W = numpy.zeros((1,4),float)
i = 0
j = 0
with open("1t.sp", "r") as inFile:
with open("2t.sp","w") as outFile:
line = inFile.readline()
while (line != ""):
newLine = []
for words in line.split():
if words.startswith("W="):
W[0,i] = float(words[2:].replace('n',''))*random.normalvariate(1,widthDeviation)
#print i,words,str('W='+str(W[i]).strip('[]')+'n').replace(" ","")
words = str('W='+str(W[0,i]).strip('[]')+'n').replace(" ","")
i = i+1
elif words.startswith("L="):
L[0,j] = float(words[2:].replace('n',''))*random.normalvariate(1,lengthDeviation)
#print j,words,str('L='+str(L[j]).strip('[]')+'n').replace(" ","")
words = str('L='+str(L[0,j]).strip('[]')+'n').replace(" ","")
j = j+1
newLine.append(words)
#print newLine
outFile.write(" ".join(newLine))
outFile.write("\n")
line = inFile.readline()
outFile.close()
inFile.close()
openWrite.write(str(W).strip('[]'))
openWrite.write(str(L).strip('[]'))
call(["make"])
fRate = (open("tf.log","r").readlines()[34]).split()[-2]
cSect = (open("tf.log","r").readlines()[35]).split()[-2]
openWrite.write("\t")
openWrite.write(fRate)
openWrite.write(" ")
openWrite.write(cSect)
openWrite.write("\n")
openWrite.close()