How to parallelize csh script with nested loop

341 views Asked by At

I have four different experiment factors.

For each of the experiments I need to vary three parameters and call a fortran program. I pass the parameters to the fortran program using an EOF construction.

Here is an example of the code:

set expfac=(0.1 0.3 0.5 0.7)
set fact1=(1 3 2 8)
set fact2=(9 2 1 4)
set fact3=(5 6 1 4)

@ exp = 1
while ( $exp <= $#expfac )
 foreach i ($fact1)
   foreach k ($fact2)
    foreach h ($fact3)
 ./PROGRAM << EOF
expfac     |$expfac[$exp]
fact1      |${i}
fact2      |${k}
fact3      |${h}
EOF
   end
  end
 end
@ exp += 1
end

How can I parallelize respect to the while loop? Using GNU parallel maybe?

1

There are 1 answers

0
Ole Tange On

My csh skills are crap, so here it is in bash:

parallel --header : './PROGRAM << EOF
expfac     |{expfac}
fact1      |{fact1}
fact2      |{fact2}
fact3      |{fact3}
EOF' ::: expfac 0.1 0.3 0.5 0.7 ::: fact1 1 3 2 8 ::: fact2 9 2 1 4 ::: fact3 5 6 1 4

The above will unfortunately fail if the values include characters that need shell quoting ("&\'* and the likes). From your example it seems it will not be a problem for you, though.