function runprop = slurmSingleTask( runprop )
% slurmSingleTask - decode function

% Copyright 2017-2019 The MathWorks, Inc.

JOB_ID  = getenv('SLURM_JOBID');
TASK_ID = getenv('SLURM_ARRAY_TASK_ID');
if isempty(TASK_ID) % not using job arrays
    TASK_ID = getenv('MDCE_TASK_ID');
else % are using job arrays
    IDOffset = getenv('PARALLEL_SERVER_TASK_ID_OFFSET');
    if ~isempty(IDOffset)
        TASK_ID = num2str( str2double(TASK_ID) + str2double(IDOffset) );
    end
end

storageConstructor = parallel.internal.cluster.getParallelServerEnv('PARALLEL_SERVER_STORAGE_CONSTRUCTOR');
storageLocation    = parallel.internal.urldecode( parallel.internal.cluster.getParallelServerEnv('PARALLEL_SERVER_STORAGE_LOCATION') );
jobLocation        = parallel.internal.cluster.getParallelServerEnv('PARALLEL_SERVER_JOB_LOCATION');
taskLocation       = [jobLocation filesep 'Task' TASK_ID ];

% Need to tell the job runner where its dependency directory is
dependencyDir = [tempdir JOB_ID '.' TASK_ID '.mps.temp'];

set(runprop, ...
    'StorageConstructor', storageConstructor, ...
    'StorageLocation', storageLocation, ...
    'JobLocation', jobLocation, ....
    'TaskLocation', taskLocation, ...
    'DependencyDirectory', dependencyDir, ...
    'LocalSchedulerName', 'parallel.cluster.Slurm', ...
    'FallbackSchedulerName', 'parallel.cluster.TaskRunner');
