matRad_compileOmpMCInterface

Purpose ^

Compiles the ompMC interface (integrated as submodule)

Synopsis ^

function matRad_compileOmpMCInterface(dest,omcFolder)

Description ^

 Compiles the ompMC interface (integrated as submodule)

 call
   matRad_compileOmpMCInterface()
   matRad_compileOmpMCInterface(dest)
   matRad_compileOmpMCInterface(dest,sourceFolder)

 input:
   dest:           (optional) destination for mex file. Default: location 
                   of this file
   sourceFolder:   (optional) path to ompMC . Default assumes its checked
                   out in the submodules folder of matRad

 References


 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Copyright 2020 the matRad development team. 
 
 This file is part of the matRad project. It is subject to the license 
 terms in the LICENSE file found in the top-level directory of this 
 distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 
 of the matRad project, including this file, may be copied, modified, 
 propagated, or distributed except according to the terms contained in the 
 LICENSE file.

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cross-reference information ^

This function calls: This function is called by:

Source code ^

0001 function matRad_compileOmpMCInterface(dest,omcFolder)
0002 % Compiles the ompMC interface (integrated as submodule)
0003 %
0004 % call
0005 %   matRad_compileOmpMCInterface()
0006 %   matRad_compileOmpMCInterface(dest)
0007 %   matRad_compileOmpMCInterface(dest,sourceFolder)
0008 %
0009 % input:
0010 %   dest:           (optional) destination for mex file. Default: location
0011 %                   of this file
0012 %   sourceFolder:   (optional) path to ompMC . Default assumes its checked
0013 %                   out in the submodules folder of matRad
0014 %
0015 % References
0016 %
0017 %
0018 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 %
0020 % Copyright 2020 the matRad development team.
0021 %
0022 % This file is part of the matRad project. It is subject to the license
0023 % terms in the LICENSE file found in the top-level directory of this
0024 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0025 % of the matRad project, including this file, may be copied, modified,
0026 % propagated, or distributed except according to the terms contained in the
0027 % LICENSE file.
0028 %
0029 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0030 
0031  
0032 matRad_cfg = MatRad_Config.instance();
0033 
0034 env = matRad_getEnvironment();
0035 
0036 if nargin < 1
0037     dest = fileparts(mfilename('fullpath'));
0038 end
0039 
0040 if nargin < 2
0041     omcFolder = [matRad_cfg.matRadRoot filesep 'submodules' filesep 'ompMC'];
0042 end
0043 
0044 sourceFolder = [omcFolder filesep 'src'];
0045 interfaceFolder = [omcFolder filesep 'ucodes' filesep 'omc_matrad'];
0046 
0047 mainFile = [interfaceFolder filesep 'omc_matrad.c'];
0048 
0049 addFiles = {'ompmc.c','omc_utilities.c','omc_random.c'};
0050 addFiles = cellfun(@(f) fullfile(sourceFolder,f),addFiles,'UniformOutput',false);
0051 
0052 addFiles = strjoin(addFiles,' ');
0053 
0054 if exist ('OCTAVE_VERSION','builtin')
0055     ccName = eval('mkoctfile -p CC');
0056 else
0057     myCCompiler = mex.getCompilerConfigurations('C','Selected');
0058     ccName = myCCompiler.ShortName;
0059 end
0060 
0061 %These settings have only been tested for MSVC and g++. You may need to adapt for other compilers
0062 if ~isempty(strfind(ccName,'MSVC')) %Not use contains(...) because of octave
0063     flags{1,1} = 'COMPFLAGS';
0064     flags{1,2} = '/openmp';
0065     flags{2,1} = 'OPTIMFLAGS';
0066     flags{2,2} = '/O2';
0067 else
0068     flags{1,1} = 'CFLAGS';
0069     flags{1,2} = '-std=gnu99 -fopenmp -O3';
0070     flags{2,1} = 'LDFLAGS';
0071     flags{2,2} = '-fopenmp';
0072     
0073 end
0074 
0075 includestring =  ['-I' sourceFolder];
0076 
0077 flagstring = '';
0078 
0079 %For Octave, the flags will be set in the environment, while they
0080 %will be parsed as string arguments in MATLAB
0081 for flag = 1:size(flags,1)
0082     if strcmp(env,'OCTAVE')
0083         preFlagContent = eval(['mkoctfile -p ' flags{flag,1}]);
0084         if ~isempty(preFlagContent)
0085             preFlagContent = preFlagContent(1:end-1); %Strip newline
0086         end
0087         newContent = [preFlagContent ' ' flags{flag,2}];
0088         setenv(flags{flag,1},newContent);
0089         matRad_cfg.dispDebug('Set compiler flag %s to %s\n',flags{flag,1},newContent);
0090     else
0091         flagstring = [flagstring flags{flag,1} '="$' flags{flag,1} ' ' flags{flag,2} '" '];
0092     end
0093 end
0094 
0095 mexCall = ['mex -largeArrayDims ' flagstring ' ' includestring ' ' mainFile ' ' addFiles];
0096 matRad_cfg.dispDebug('Compiler call: %s\n',mexCall);
0097 
0098 currDir = pwd;
0099 cd(dest);
0100 eval(mexCall);
0101 cd(currDir);
0102 end

| Generated by m2html © 2005