Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:18:31

0001 #! /bin/bash
0002 
0003 ### Stephen Kay, University of York
0004 ### 22/04/24
0005 ### stephen.kay@york.ac.uk
0006 ### A script to create and submit jobs to the JLab farm.
0007 ### As is, takes 4 arguments, number of files, number of events per file, then two example arguments.
0008 ### Arg3/Arg4 could be something you feed your specific script, add or remove as needed.
0009 
0010 SimDir="/group/eic/users/${USER}/ePIC/" # Put in the path of your directory here (where your eic-shell is)
0011 echo "Running as ${USER}"
0012 echo "Assuming simulation directory - ${SimDir}"
0013 if [ ! -d $SimDir ]; then   
0014     echo "!!! WARNING !!!"
0015     echo "!!! $SimDir - Does not exist - Double check pathing and try again !!!"
0016     echo "!!! WARNNING !!!"
0017     exit 1
0018 fi
0019 
0020 NumFiles=$1 # First arg is the number of files to run
0021 if [[ -z "$1" ]]; then
0022     echo "I need a number of files to run!"
0023     echo "Please provide a number of files to run as the first argument"
0024     exit 2
0025 fi
0026 NumEvents=$2 # Second argument is an output file name
0027 if [[ -z "$2" ]]; then
0028     echo "I need a number of events to generate per file!"
0029     echo "Please provide a number of event to generate per file as the second argument"
0030     exit 3
0031 fi
0032 
0033 if [[ -z "$3" ]]; then # Third argument - something passed to the script, default to 10
0034     Arg3=10
0035     echo "Arg3 not specified, defaulting to 10"
0036 fi
0037 
0038 # Check if a fourth argument is provided, pass something to script. Default to 10
0039 if [[ -z "$4" ]]; then
0040     Arg4=10
0041     echo "Arg4 not specified, defaulting to 10"
0042 fi
0043 
0044 # For now, output to /volatile. Change if you want to keep files longer
0045 echo; echo; echo "!!!!! NOTICE !!!!!"; echo "For now, the outputs generated by jobs from this script will go to a directory under /volatile, change this if you want to keep the files for longer!"; echo "!!!!! NOTICE !!!!!"; echo; echo;
0046 if [ ! -d "/volatile/eic/${USER}" ]; then
0047     read -p "It looks like you don't have a directory in /volatile/eic, make one? <Y/N> " prompt
0048     if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
0049         echo "Making a directory for you in /volatile/eic"
0050         mkdir "/volatile/eic/${USER}"
0051     else
0052         echo "If I don't make the directory, I won't have anywhere to output files!"
0053         echo "Ending here, modify the script and change the directories/paths if you actually want to run this script!"
0054         exit 4
0055     fi
0056 fi
0057 
0058 OutputPath="/volatile/eic/${USER}" # Specify your output path
0059 if [ ! -d $OutputPath ]; then
0060     echo "It looks like the output path doesn't exist."
0061     echo "The script thinks this should be - ${OutputPath}"
0062     read -p "Make this directory? <Y/N> " prompt2
0063     if [[ $prompt2 == "y" || $prompt2 == "Y" || $prompt2 == "yes" || $prompt2 == "Yes" ]]; then
0064         echo "Making directory - ${OutputPath}"
0065         mkdir $OutputPath
0066     else
0067         echo "If I don't make the directory, I won't have anywhere to output files!"
0068         echo "Ending here, modify the script and change the directories/paths if you actually want to run this script!"
0069         exit 5
0070     fi
0071 fi
0072 
0073 Timestamp=$(date +'%d_%m_%Y')
0074 Workflow="ePIC_Sim_${USER}_${Timestamp}" # Change this as desired
0075 export EICSHELL=${SimDir}/eic-shell # Must point to where your eic-shell is!
0076 # Define a disk space request. Change depending upon your needs. 
0077 Disk_Space=$(( (($NumEvents +(5000/2) ) /5000) +1 )) # Request disk space depending upon number of simulated events requested, always round up to nearest integer value of GB, add 1 GB at end for safety too
0078 for (( i=1; i<=$NumFiles; i++ ))
0079 do
0080     Output_tmp="$OutputPath/Sim_${i}_${NumEvents}_${Arg3/./p}_${Arg4/./p}"
0081     if [ ! -d "${Output_tmp}" ]; then
0082         mkdir $Output_tmp
0083     else
0084         if [ "$(ls -A $Output_tmp)" ]; then # If directory is NOT empty, prompt a warning
0085             echo "!!!!! Warning, ${Output_tmp} directory exists and is not empty! Files may be overwritten! !!!!!"
0086         fi
0087     fi
0088     batch="${SimDir}/Sim_${i}_${NumEvents}_${Arg3}_${Arg4}.txt" # This is where the job file will be created, change as desired
0089     echo "Running ${batch}"
0090     cp /dev/null ${batch}
0091     echo "PROJECT: eic" >> ${batch}
0092     echo "TRACK: analysis" >> ${batch}    
0093     echo "JOBNAME: ePIC_Sim_${i}_${NumEvents}_${Arg3}_${Arg4}" >> ${batch}
0094     if  [[ $NumEvents -ge 15000 ]]; then # If over 15k events per file, request 6 GB per job
0095         echo "MEMORY: 6000 MB" >> ${batch}
0096     else
0097         echo "MEMORY: 4000 MB" >> ${batch}
0098     fi
0099     echo "DISK_SPACE: ${Disk_Space} GB" >> ${batch} # Simulation output is the largest hog for this, request 1GB for 5k events simulated - See calculation before the for loop
0100     echo "CPU: 1" >> ${batch}
0101     echo "TIME: 1440" >> ${batch} # 1440 minutes -> 1 day
0102     # The line below is the "guts" of this script. This is the script or job we will actually run on the farm node. Change the pathing to your script as needed. Submit the args as needed.
0103     echo "COMMAND:${SimDir}/JLab_Farming_Job.sh ${i} ${NumEvents} ${Arg3} ${Arg4}" >> ${batch}
0104     echo "MAIL: ${USER}@jlab.org" >> ${batch} # Modify as desired
0105     echo "Submitting batch job"
0106     eval "swif2 add-jsub ${Workflow} -script ${batch} 2>/dev/null" # Add our created job to the swif2 workflow
0107     echo " "
0108     sleep 2
0109     rm ${batch} # Remove the job script after submission
0110 done
0111 
0112 eval 'swif2 run ${Workflow}'
0113 
0114 exit 0