<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.ccn.ucla.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Hoffman2%3ASoftware_Tools%3A_FMRIprep%3A_Job_Array_Example-v20.2</id>
	<title>Hoffman2:Software Tools: FMRIprep: Job Array Example-v20.2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.ccn.ucla.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Hoffman2%3ASoftware_Tools%3A_FMRIprep%3A_Job_Array_Example-v20.2"/>
	<link rel="alternate" type="text/html" href="https://www.ccn.ucla.edu/wiki/index.php?title=Hoffman2:Software_Tools:_FMRIprep:_Job_Array_Example-v20.2&amp;action=history"/>
	<updated>2026-05-08T16:34:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://www.ccn.ucla.edu/wiki/index.php?title=Hoffman2:Software_Tools:_FMRIprep:_Job_Array_Example-v20.2&amp;diff=4406&amp;oldid=prev</id>
		<title>Jpdiaz: fmriprep as job array example</title>
		<link rel="alternate" type="text/html" href="https://www.ccn.ucla.edu/wiki/index.php?title=Hoffman2:Software_Tools:_FMRIprep:_Job_Array_Example-v20.2&amp;diff=4406&amp;oldid=prev"/>
		<updated>2020-09-29T04:34:02Z</updated>

		<summary type="html">&lt;p&gt;fmriprep as job array example&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;running fmriprep-20.1.1 as a job array&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Job array is a type of batch mode. It makes it possible to process different subjects using the same script on multiple Hoffman2 working nodes at the same time (or as nodes become available).&lt;br /&gt;
It can be used to submit hundreds of subjects to be processed at once.&lt;br /&gt;
This can be done using two scripts, submit_fmriprep_jobarray.sh and run_fmriprep.sh.&lt;br /&gt;
The first script, submit_fmriprep_jobarray.sh, will (1). pass the job configuration to qsub, (2). initiate the job environment, and (3). schedule the job to run fmriprep on each of the 8 subject in this example:&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 #$ -cwd -V                      # use current work dir and env for job&lt;br /&gt;
 #$ -o joblog.$JOB_ID.$TASK_ID   # write log (add Job/Index to name)&lt;br /&gt;
 #$ -j y                         # merge error log with job log&lt;br /&gt;
 #$ -l h_rt=22:00:00,h_data=20G  # request 22 hours and 100GB total&lt;br /&gt;
 #$ -pe shared 5                 # request 5 cpus&lt;br /&gt;
 #$ -m a                         # email about aborted runs only&lt;br /&gt;
 #$ -t 1-8:1   	                 # array index (adjust for N subjects)&lt;br /&gt;
 &lt;br /&gt;
 # initiate job environment&lt;br /&gt;
 . /u/local/Modules/default/init/modules.sh&lt;br /&gt;
 module use /u/project/CCN/apps/modulefiles&lt;br /&gt;
 &lt;br /&gt;
 module load fsl/5.0.9&lt;br /&gt;
 module load freesurfer/6.0.0&lt;br /&gt;
 module load ants/ants-2.3.1  # requires 2.3.1 or --use-syn-sdc will fail&lt;br /&gt;
 module load afni/19.0.15&lt;br /&gt;
 module load itksnap/3.6.0-RC1.QT4&lt;br /&gt;
 module load hcp/1.3.2&lt;br /&gt;
 module load python/3.7.0&lt;br /&gt;
 module load ica-aroma/0.4.5  # requires 0.4.5 or --use-aroma will fail&lt;br /&gt;
 module load fmriprep/20.1.1&lt;br /&gt;
 &lt;br /&gt;
 # export paths and settings&lt;br /&gt;
 export PATH=/u/project/CCN/apps/c3d/c3d-1.0.0-Linux-x86_64/bin/:$PATH&lt;br /&gt;
 export NO_FSL_JOBS=true&lt;br /&gt;
 &lt;br /&gt;
 # Declare the subjects list&lt;br /&gt;
 declare -a sublist&lt;br /&gt;
 &lt;br /&gt;
 SUBS[0]=&amp;#039;01&amp;#039;&lt;br /&gt;
 SUBS[1]=&amp;#039;02&amp;#039;&lt;br /&gt;
 SUBS[2]=&amp;#039;03&amp;#039;&lt;br /&gt;
 SUBS[3]=&amp;#039;04&amp;#039;&lt;br /&gt;
 SUBS[4]=&amp;#039;05&amp;#039;&lt;br /&gt;
 SUBS[5]=&amp;#039;06&amp;#039;&lt;br /&gt;
 SUBS[6]=&amp;#039;07&amp;#039;&lt;br /&gt;
 SUBS[7]=&amp;#039;08&amp;#039;&lt;br /&gt;
 &lt;br /&gt;
 ## subjects can also be read from a file:&lt;br /&gt;
 # readarray -t SUBS &amp;lt; subjects.txt&lt;br /&gt;
 &lt;br /&gt;
 # initiate count for array submission&lt;br /&gt;
 (( i=$SGE_TASK_ID - 1 ))&lt;br /&gt;
 echo &amp;quot;This is sub-job $SGE_TASK_ID, --n-cpus $NSLOTS&amp;quot;&lt;br /&gt;
 echo &amp;quot;This is subject ${SUBS[$i]}&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # pass subject ID and number of cpus to second script&lt;br /&gt;
 ./run_fmriprep.sh ${SUBS[$i]} $NSLOTS&lt;br /&gt;
 &lt;br /&gt;
 # ~ done! ~&lt;br /&gt;
&lt;br /&gt;
In total, 8 separate jobs will be created after running the script above.&lt;br /&gt;
Using the command qstat -u USERNAME will show a single job array until they begin running, as nodes become available.&lt;br /&gt;
The second script, run_fmriprep.sh, includes all the project-specific parameters that will be passed to the fmriprep command at the end.&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 &lt;br /&gt;
 # # SET PARAMETERS ##############&lt;br /&gt;
 SUB=$1                        # a space delimited list of participant identifiers&lt;br /&gt;
 CPUS=$2                       # number of processors requested for each job&lt;br /&gt;
 WORKPATH=${SCRATCH}           # send intermediate files to scratch folder&lt;br /&gt;
 PIPENAME=&amp;#039;fmriprep-20.1.1&amp;#039;  # name of output folder in derivatives&lt;br /&gt;
 BIDSPATH=&amp;#039;/u/project/usergroup/data/BIDS_PROJECT&amp;#039;&lt;br /&gt;
 &lt;br /&gt;
 # project-specific flags for fmriprep&lt;br /&gt;
 ADDFLAGS=&amp;#039;--use-aroma --use-syn-sdc --output-spaces MNI152NLin6Asym MNIPediatricAsym:cohort-1:res-2 --resource-monitor --bids-filter-file bids.json&amp;#039;&lt;br /&gt;
 freesurfer_license=&amp;#039;/u/project/CCN/apps/freesurfer/6.0.0/LICENSE&amp;#039;&lt;br /&gt;
 &lt;br /&gt;
 # # FMRIPREP COMMAND ############&lt;br /&gt;
 fmriprep ${ADDFLAGS} -w ${WORKPATH} \&lt;br /&gt;
  --participant_label ${SUB} --fs-license-file ${freesurfer_license} \&lt;br /&gt;
  ${BIDSPATH}/rawdata ${BIDSPATH}/derivatives/${PIPENAME} participant \&lt;br /&gt;
  --n-cpus ${CPUS} --mem_mb 98000&lt;br /&gt;
 &lt;br /&gt;
 # ~ done! ~&lt;br /&gt;
&lt;br /&gt;
A few things to note:&lt;br /&gt;
(1).  the module versions are different for the new version of fmrirpep&lt;br /&gt;
(2). $SCRATCH is a 2TB working directory for temporary files.&lt;br /&gt;
SCRATCH=/u/scratch/[u]/[username]&lt;br /&gt;
Sending fmriprep scratch files here helps save space in your group project directory.&lt;br /&gt;
These files will be automatically deleted after 7 days.&lt;br /&gt;
Call the CCN script, clear_scratch.sh, to clear those temporary files if necessary.&lt;br /&gt;
(3). fmriprep takes in environmental information to optimize its parallel processing.&lt;br /&gt;
Unfortunately, since it is not run in a container, fmriprep sometimes gets input about the entire cluster node and thinks it has access to more resources than requested.&lt;br /&gt;
The system will usually kill jobs that exceed the requested limit.&lt;br /&gt;
To prevent this, use  --n-cpus and --mem_mb to limit fmriprep to the number of resources requested for the job.&lt;br /&gt;
For --mem_mb it’s recommended to specify an amount just below the total amount of memory requested as fmriprep sometimes spills over the limit.&lt;/div&gt;</summary>
		<author><name>Jpdiaz</name></author>
	</entry>
</feed>