【发布时间】:2018-03-20 12:51:13
【问题描述】:
enter code here MPI 程序采用 3 个命令行参数(2 个输入文件和 SIZE,这对文件对来说是相同的)。例如,在同一目录中,我有这些文件。
abc.mtx, abc.txt SIZE is same for these 2 files
def.mtx, def.txt SIZE is same for these two files
qas.mtx, qas.txt SIZE is same for these two files
and so on .....
请注意:文件名相同但扩展名不同。
我想运行我的代码
mpirun -np 4 ./myexe file1.mtx file1.txt -SIZE 10 //.myexe is executable
我想用不同数量的进程执行我的程序,比如 -np 2、4、6、8 和 10。我有一百多个文件。我想从命令行执行我的代码一次,使用指定的进程数一一读取这些文件。
例如
abc.mtx and abc.txt should run first with 2,4,6,8,10 processes
and then next two files def.mtx and def.txt with 2,4,6,8,10 processes and so on....
对于串行代码,我尝试了以下命令,它通过一个一个地获取所有 .txt 文件来工作。(仅适用于 txt 或 mtx 文件,但不能同时使用)
find . -name "*.txt" | awk -F"/" '{system ("./myexe." $2)}'
如何使用 2 个具有不同扩展名的输入文件运行,即(mtx、txt)。第三个参数是 SIZE 的最佳方法是什么。我是否应该创建另一个包含 SIZE 并提供三个输入文件参数作为输入的文件。?
编辑 这是一个脚本
#!/bin/bash
while read base size; do
mtx="${base}.mtx"
txt="${base}.txt"
for np in 2 4 6 8 10; do
echo mpirun -np $np ./myexe "$mtx" "$txt" -SIZE $size
done
done < jobs
jobs.txt 文件看起来像
bus 490
bcs_B 10
arc 1178
tk18 99
我正在使用以下命令来执行
./script.sh jobs.txt ./new
也试过
bash script.sh jobs.txt ./new
编辑 2
Jobs.txt 看起来像
494_bus 494
arc130 130
bcsstk02 66
bcsstk18 11948
脚本是
#!/bin/bash
while read base size; do
mtx="${base}.mtx"
txt="${base}.txt"
for np in 2 4; do
mpirun -np $np ./new "$txt" "$mtx" -SIZE $size
done
done < "$1"
我只是从我的代码中打印矩阵的维度。输出是
Dimension of the matrix is = 494
Dimension of the matrix is = 494
Dimension of the matrix is = 494
Dimension of the matrix is = 494
Dimension of the matrix is = 494
Dimension of the matrix is = 494
它只取第一对文件,用 -np 2 和 -np 4 执行它们,但不执行其余的。
如果我在 mpirun 显示之前在脚本中编写 Echo
mpirun -np 2 ./new 494_bus.txt 494_bus.mtx -SIZE 494
mpirun -np 4 ./new 494_bus.txt 494_bus.mtx -SIZE 494
mpirun -np 2 ./new arc130.txt arc130.mtx -SIZE 130
mpirun -np 4 ./new arc130.txt arc130.mtx -SIZE 130
mpirun -np 2 ./new bcsstk02.txt bcsstk02.mtx -SIZE 66
mpirun -np 4 ./new bcsstk02.txt bcsstk02.mtx -SIZE 66
mpirun -np 2 ./new bcsstk18.txt bcsstk18.mtx -SIZE 11948
mpirun -np 4 ./new bcsstk18.txt bcsstk18.mtx -SIZE 11948
如果我分别执行这些命令中的每一个,它们都可以正常工作。例如
mpirun -np 4 ./new arc130.txt arc130.mtx -SIZE 130
mpirun -np 2 ./new bcsstk18.txt bcsstk18.mtx -SIZE 11948
这些运行命令可以正常工作,但不能与脚本一起运行。 谢谢
编辑 3
cat jobs.txt
494_bus 494
arc130 130
bcsstk02 66
bcsstk18 11948
cat -vet jobs.txt
494_bus 494$
arc130 130$
bcsstk02 66$
bcsstk18 11948$
猫脚本.sh
#!/bin/bash
while read base size; do
mtx="${base}.mtx"
txt="${base}.txt"
for np in 2 4; do
mpirun -np $np ./new "$txt" "$mtx" -SIZE $size
done
done < "$1"
cat -vet script.sh
#!/bin/bash$
$
while read base size; do$
mtx="${base}.mtx"$
txt="${base}.txt"$
for np in 2 4; do$
mpirun -np $np ./new "$txt" "$mtx" -SIZE $size$
done$
done < "$1"$
编辑 4
bash -xv script2.sh jobs.txt
#!/bin/bash
while read base size; do
mtx="${base}.mtx"
txt="${base}.txt"
for np in 2 4; do
mpirun -np $np ./new "$txt" "$mtx" -SIZE $size
done
done < "$1"
+ read base size
+ mtx=494_bus.mtx
+ txt=494_bus.txt
+ for np in 2 4
+ mpirun -np 2 ./new 494_bus.txt 494_bus.mtx -SIZE 494
Dimension of the matrix is = 494
Dimension of the matrix is = 494
+ for np in 2 4
+ mpirun -np 4 ./new 494_bus.txt 494_bus.mtx -SIZE 494
Dimension of the matrix is = 494
Dimension of the matrix is = 494
Dimension of the matrix is = 494
Dimension of the matrix is = 494
+ read base size
【问题讨论】:
-
我没有看到任何 C....
-
也不是真正的 MPI 问题 ...
-
为什么要使用 [batch-file] 标签,而您显然想要
bash?
标签: bash