Skip to content

Commit

Permalink
moves mex files and adapt installation
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfHielscher committed Feb 1, 2018
1 parent 61d7855 commit 6630249
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 200 deletions.
1 change: 1 addition & 0 deletions extern/nfft/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mex*
1 change: 1 addition & 0 deletions extern/nfft_openMP/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mex*
13 changes: 13 additions & 0 deletions extern/nfft_openMP/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

1. Download the FFTW

2. Download the NFFT

3. in a terminal do
./bootstrap
./configure --with-matlab=MATLAB_DIR --enable-nfsoft --enable-nfsft --enable-openmp --enable-portable-binary
make

4. copy the following files into this directory
nfft/matlab/nfsoft/nfsoftmex.mex*
nfft/matlab/nfsoft/nfsftmex.mex*
6 changes: 1 addition & 5 deletions geometry/@quaternion/Euler.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@
elseif check_option(varargin,'nfft')

alpha = fft_rho(alpha);
if getMTEXpref('nfft_bug')
beta = fft_theta(-beta);
else
beta = fft_theta(beta);
end
beta = fft_theta(beta);
gamma = fft_rho(gamma);
varargout{1} = 2*pi*[alpha(:),beta(:),gamma(:)].';

Expand Down
1 change: 1 addition & 0 deletions mex/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mex*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 3 additions & 12 deletions c/mex/mex_install.m → mex/mex_install.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@ function mex_install(mtexpath,varargin)
% compiles all mex files for use with MTEX

if nargin == 0, mtexpath = mtex_path;end
mexpath = fullfile(mtexpath,'c','mex');
mexpath = fullfile(mtexpath,'mex');
mexfile = @(file)fullfile(mexpath,file);

% check whether to set largeArrayDims option
if nargin <= 2 && newer_version(7.3)
if strfind(computer,'64')
varargin = {'-largeArrayDims'};
else
varargin = {'-compatibleArrayDims'};
end
end

places = strcat({'S1Grid','S2Grid','SO3Grid'}, '_*.c');

% compile all the files
Expand All @@ -22,9 +13,9 @@ function mex_install(mtexpath,varargin)
files = {files.name};
for f = 1:length(files)
if exist(mexfile(files{f}),'file')
disp(['... compile ',files{f}]);
disp(['... compiling ',files{f}]);
try
mex(varargin{:},'-outdir',mexfile(getMTEXpref('architecture')),mexfile(files{f}));
mex('-largeArrayDims',mexfile(files{f}));
catch %#ok<CTCH>
disp(['Compiling ' mexfile(files{f}) ' failed!']);
end
Expand Down
4 changes: 1 addition & 3 deletions startup_mtex.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function startup_mtex(varargin)
% mtex_settings.m in this directory.
%


% this is a bugfix for MATLAB having very high cpu load on idle
if isunix && ~ismac
try
Expand All @@ -16,7 +15,6 @@ function startup_mtex(varargin)
end
end


% Check MATLAB version
% --------------------
lasterr('') %#ok<LERR> %reset all errors
Expand Down Expand Up @@ -153,7 +151,7 @@ function do_install(local_path)
% set MTEX search path
function setMTEXPath(local_path)

exclPath = {'c','data','help','templates'};
exclPath = {'c','data','help','templates','nfft'};

if ~MATLABverLessThan('8.1')
exclPath = [exclPath,'8.4'];
Expand Down
229 changes: 49 additions & 180 deletions tools/misc_tools/check_installation.m
Original file line number Diff line number Diff line change
@@ -1,164 +1,77 @@
function check_installation
% check whether all binaries are working properly

% check tmp dir
if strfind(getMTEXpref('tempdir',tempdir),' ')
hline()
disp('Warning: The path MTEX uses for temporary files');
disp([' tempdir = ''' getMTEXpref('tempdir') '''']);
disp('contains white spaces!');
disp(['Please change this in your <a href="matlab:edit mtex_settings.m">' ...
'mtex_settings.m</a>!']);
% check nfft
if ~check_nfft

rmpath([mtex_path filesep 'extern' filesep 'nfft_openMP'])
addpath([mtex_path filesep 'extern' filesep 'nfft'])

hline()
end

% check binaries
check_binaries;

% check mex binaries
check_mex;
if check_nfft

disp(' ');
disp(' MTEX: Error running NFFT with openmp - I''m going to use it without openmp!');

else

% check for nfft bug
setMTEXpref('nfft_bug',0);
try
setMTEXpref('nfft_bug',~checkNfftBug);
catch
disp(' ');
disp(' MTEX: Error running NFFT!');
disp(' ');
disp(' The original error message was:');
e = lasterror;
disp([' ' e.message]);

disp(' ');
disp(' Try to compile the binaries or contact author for help!');

end
hline()
end


% check mex
check_mex;

end

% ------------ check for binaries --------------------------
function check_binaries

% check binaries do exist
fast_check_binaries;
% -------- check nfft

[th,rh] = polar(equispacedS2Grid('points',10));

th = fft_theta(th);
rh = fft_rho(rh);

gh = [reshape(rh,1,[]);reshape(th,1,[])];
r = [reshape(rh,1,[]);reshape(th,1,[])];

c = ones(size(th));

Al = ones(size(th));
setpref('mtex','binaries',false);
function e = check_nfft

e = 0;
try

f = call_extern('odf2pf','EXTERN',gh,r,c,Al);
assert(any(f));

setpref('mtex','binaries',true);

catch %#ok<*CTCH>
% check NFSFT
f = @(x) x.theta;
sF = S2FunHarmonic.quadrature(f,'bandwidth',12);
assert(abs(f(xvector) - sF.eval(xvector))<1e-5);

if ismac && strcmp(getMTEXpref('architecture'),'maci') % maybe it is a 64 bit mac
try
setMTEXpref('architecture','maci64');
f = call_extern('odf2pf','EXTERN',gh,r,c,Al);
assert(any(f));
setpref('mtex','binaries',true);
return
catch
setMTEXpref('architecture','maci');
end
end

hline()
disp(' MTEX binary check failed!');
disp(' ');
disp(' The original error message was:');
e = lasterror; %#ok<*LERR>
disp([' ',e.message]);

disp(' ');
disp(' Check the following options:');
disp([' * ' doclink('compilation','Compile') ' the binaries yourself.']);
disp(' * Ask the maintainer for help!');
hline()
% check NFSOFT
ori = orientation.rand(100,crystalSymmetry);
odf = calcODF(ori,'Fourier','bandwidth',12);
odf.eval(ori);
e = 1;
end

end

function fast_check_binaries

if ispc, mtex_ext = '.exe';else mtex_ext = '';end
binariespath = fullfile(mtex_path,'c','bin',getMTEXpref('architecture'));
binaries = {'pf2odf','pdf2pf','odf2pf','odf2fc','fc2odf'};

% check for existence
for k=1:numel(binaries)
prg = fullfile(binariespath,binaries{k});
if ~exist([prg mtex_ext],'file'),
warning(['missing binary ' binaries{k} mtex_ext])
return;
end
end

end

% ----------- check mex files ---------------------------
% ----------- check mex files ---------------------------
function check_mex

% set mex/directory
mexpath = fullfile(mtex_path,'c','mex',getMTEXpref('architecture'));
addpath(mexpath,0);

% check for mex files
if fast_check_mex(mexpath), return;end
if fast_check_mex, return;end

hline('-');
disp('Checking mex files failed!');

% check old mex version
if exist(fullfile(mexpath,'v7.1'),'dir')

% change path
rmpath(mexpath);
addpath(fullfile(mexpath,'v7.1'));
disp('> Trying now with older version.');
if fast_check_mex(mexpath)
disp('> Hurray - everythink works!')
disp(' ');
try
copyfile(fullfile(mexpath,'v7.1','*.*'),mexpath,'f');
% restore path
rmpath(fullfile(mexpath,'v7.1'));
addpath(mexpath);
catch
hline()
disp('> Error while copying!')
disp('> You should copy');
disp([' ' fullfile(mexpath,'v7.1')]);
disp(' to ');
disp([' ', mexpath]);
disp('> before starting the next session');
hline()
disp(' ');
end
return
else
disp('> Checking old mex files failed!');
% restore path
rmpath(fullfile(mexpath,'v7.1'));
addpath(mexpath);
end
end

disp('> Trying now to recompile mex files.');
opwd = pwd;
cd(fullfile(mtex_path,'c','mex'));
cd(fullfile(mtex_path,'mex'));
mex_install(mtex_path,false);
cd(opwd);

if ~fast_check_mex(mexpath)
% disp('> Hurray - everythink works!')
% else
if fast_check_mex
disp('> Hurray - everythink works!')
else
hline()
disp(' MTEX: Couldn''t get the mex files working!');
disp(' ');
Expand All @@ -175,16 +88,17 @@

% ----------------------------------------------------------------------

function e = fast_check_mex(mexpath)
function e = fast_check_mex

e = false;
mexpath = [mtex_path filesep 'mex'];

% check for existence
% check for existence of the files
mex = {'quaternion_*','S1Grid_*','S2Grid_*','SO3Grid_*'};
for k=1:numel(mex)
cfile = dir(fullfile(mexpath,'..', [mex{k} '.c']));
cfile = dir(fullfile(mexpath, [mex{k} '.c']));
for c=1:numel(cfile)
[a,cname] = fileparts(cfile(c).name);
[~,cname] = fileparts(cfile(c).name);
mexfile = fullfile(mexpath, [cname,'.' mexext]);
if ~exist(mexfile,'file')
warning(['missing mex-file ' [cname,'.' mexext]])
Expand All @@ -203,51 +117,6 @@

end

% --------------------------------------------------------------

function out = checkNfftBug

% set bandwidth
L = 2;

% set an orientation
q = axis2quat(xvector+yvector,25*degree);

% set a direction
h = vector3d(1,2,3);

% convert to export parameters
g = Euler(q,'nfft');

% set parameters
c = 1;
A = ones(1,L+1);

% run NFSOFT
D = call_extern('odf2fc','EXTERN',g,c,A); % conjugate(D)

% extract result
D = complex(D(1:2:end),D(2:2:end));

l = 1;

% rotate spherical harmonics manualy
Y = sphericalY(l,h).'; % -> Y
gY = sphericalY(l,q*h).'; % -> rotated Y

% rotate spherical harmonics by matrix D
D3 = reshape(D(2:10),3,3);

TY = D3 * Y;

% check whether spherical Y are rotated correctly by D
out = sqrt(norm(TY - gY)) < 0.001;

end


% -----------------------------------------------------------------------


function hline(st)

Expand Down

0 comments on commit 6630249

Please sign in to comment.