MODULE job_id_mod !*********************************************************************** ! DESCRIPTION: ! Retrieves the ID for a given job ID via SLURM or PBS/TORQUE. !*********************************************************************** implicit none !======================================================================= contains !======================================================================= SUBROUTINE get_job_id(jobid) implicit none !---- Arguments character(256), intent(out) :: jobid !---- Variables integer :: stat character(256) :: tmp !---- Code ! Try SLURM call get_environment_variable("SLURM_JOBID",tmp,status = stat) if (stat == 0 .and. len_trim(tmp) > 0) then jobid = trim(adjustl(tmp)) return endif ! Try PBS/TORQUE call get_environment_variable("PBS_JOBID",tmp,status = stat) if (stat == 0 .and. len_trim(tmp) > 0) then ! Extract only the part before the point in '12345.master.cluster' to get the numeric job ID jobid = trim(adjustl(tmp(1:index(tmp,'.') - 1))) return endif error stop 'Error: neither SLURM_JOB_ID nor PBS_JOBID found in environment!' END SUBROUTINE get_job_id END MODULE job_id_mod