Ok so i have a bash function that I apply on several folders:
function task(){
do_thing1
do_thing2
do_thing3
...
}
I want to run that function in parallel. So far I was using a little fork trick:
N=4 #core number
for temp_subj in ${raw_dir}/MRST*
do
((i=i%N)); ((i++==0)) && wait
task "$temp_subj" &
done
And it works great. But I decided to get something 'cleaner' and use GNU parallel:
ls -d ${raw_dir}/MRST* | parallel task {}
Problem is it's putting EVERYTHING in parallel, including the do_thing within my task function. And it is inevitably crashing because those have to be executed in a serial fashion. I tried to modify the call to parallel in many ways but nothing seems to work. Any ideas?