0

I need to run several tasks in sequence. The task names are listed in a file (jobs.txt). I use the following code (example):

#! /bin/bash

while IFS=$'\r' read -r line || [[ -n "$line" ]]; do
    echo $line
done < "jobs.txt"

It works well. However, I need to run these tasks with openmpi (in this example, change "echo $line" to "mpirun -n 4 echo $line"), then the script does not work any more... It only read the first line from "jobs.txt" and stopped.

Any idea what's the problem and how to fix it?

  • I suspect it's because the first mpirun process "eats" the standard input that you are trying to read in the loop - similar to what happens here: Problem using read command within while read loop. You may be able to prevent that by using a different file descriptor for the loop e.g. read -u3 -r line ... 3< jobs.txt but I don't know enough about OpenMPI to say whether that's the right thing to do. – steeldriver Feb 10 at 22:29
0

Yes by assigning file descriptor other than stdin problem solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.