Search code examples
shellpipempiexec

how to use mpiexec in linux shell


I have a file a.txt and each line contains a parameter. Now I want to use mpiexec to call my program such as a.out to calculate with each parameter. So I use linux shell script to handle this. The code is sample

    cat a.txt | while read line
    do
        mpiexec -v -hostfile hosts -np 16 ./a.out ${line} 
    done 

Unexpectedly, the script end after processing only one line of file a.txt. So, it is because of the wrong use of pipe? How can I tackle with this problem?


Solution

  • #!/bin/bash
    for LINE in `cat a.txt | xargs -r`; do
        mpiexec -v -hostfile hosts -np 16 ./a.out $LINE 
    done