neurolabusc / nii_preprocess

nii_preprocess adapted for LARC and ABC studies at UofSC
20 stars 9 forks source link

Using MATLAB setenv() to set PATH and LD_LIBRARY_PATH breaks pipeline on Hyperion supercomputer #5

Open reddydpusc opened 4 years ago

reddydpusc commented 4 years ago

The use of the MATLAB setenv() function to set the PATH and LD_LIBRARY_PATH environment variables breaks the environment setup up by the modules for FSL and mrtrix3 (and others) on the Hyperion supercomputer. Because these packages can be (and usually are) installed in non-standard places in server environments, the assumptions made by the nii_preprocess() pipeline as to the locations of the packages are incorrect.

Changes were made to nii_fmri/nii_batch12.m to make the program simply report non-standard installations of FSL, as long as the FSLDIR variable is set, and the path pointed to by FSLDIR and it exists and is a directory.

function fsldir = fslDirSub
    if (getenv("FSLDIR"))
        fsldir = strcat(getenv("FSLDIR"),"/");
        if exist(fsldir,"dir")
            return;
        end
    end
.
.
.
%end fslDirSub()

An overloaded version of the MATLAB setenv() function is provided in the file _setenv.m, which prevents setting PATH and LD_LIBRARY_PATH, and passes other environment variables along to the builtin MATLAB setenv(). To enable this function on the supercomputer, or if the user wishes to set the PATH and LD_LIBRARY_PATH statically ahead or execution, simply remove the underscore.

function setenv(name,value)
% an overload replacement for setenv() for static paths
% prevents setting the PATH or LD_LIBRARY_PATH environment variables
% for HPC environments, etc.  David Reddy 20201117
    if ~exist('name','var') || ~exist('value','var')
        warning('usage: setenv(name,value) [stub version for static paths]');
    else
        if (strcmp(name,'PATH') || strcmp(name,'LD_LIBRARY_PATH'))
            warning('Stub setenv() for static paths: NOT exporting %s=%s to the environment\n',name, value);
        else
            builtin('setenv',name,value);
        end
    end
end

Note that disabling the code above by using an underscore needs to be tested. If the underscore fails to disable the code so the builtin setenv() runs, I recommend placing an "_" before setenv in the code itself.

reddydpusc commented 4 years ago

A better long-term fix for this issue would be to detect the presence of SLURM and preface the use of setenv() with a function such as ~running_under_SLURM() to prevent setting PATH and LD_LIBRARY_PATH when SLURM is present. Because setting either PATH or LD_LIBRARY_PATH incorrectly can prevent finding SLURM, it might be best to do system('ps -e | grep slurred') to see if the SLURM daemon is running or not.