Linking problem: Missing symbol when using auto parallelisation in (MEX file / shared object)

Linking problem: Missing symbol when using auto parallelisation in (MEX file / shared object)

Hello all,

Sorry for such a long post - I'd be REALLY grateful if somebody could help me get to the bottom of this problem.

So I have a MATLAB MEX file (a shared object, essentially) which works perfectly when compiled for serial operation.

It is linked using the definition .map file:
FMEX {
global:
mexfunction_;
local:
*;
};

Using nm myFileName.mexa64 on the resultant object yields a list of symbols which, importantly, include:

mexfunction_

This is the symbol used by MATLAB to run the mex function. When I add the -parallel flag to my compile line, the autoparallelisation does its thing. When I then link the object (adding -liomp to the link line, of course) I get an output file as expected. All external symbols are resolved.

However, using nm on the new output file shows that it does not contain the mexfunction_ symbol (although there is something called mexfunction__kmpc_reduction_lock_0).

As a result, I get the following error when executing it in MATLAB, because of course the mexfunction_ symbol cannot be found:

Mex file entry point is missing. Please check the (case-sensitive)
spelling of mexFunction (for C MEX-files), or the (case-insensitive)
spelling of MEXFUNCTION (for FORTRAN MEX-files).
??? Invalid MEX-file '/home/thc29/Dropbox/syncTomoPIVtoolbox/code_tomoreconstruction/mxmart_large_pvr/mxmart_large_pvr_parallel.mexa64': .

Can anyone please help explain why this symbol is missing? I know this is possible because it worked for me once - for the life of me, I don't know what changed to make it stop working!

I've added a whole set of stuff below to try and help diagnose the issue...

Thanks,

Tom Clark

____________________________
IMPORTANT PARTS OF nm OUTPUT:

With the -parallel option:
0000000000000000 A FMEX
00000000002013b0 b mexfunction__kmpc_reduction_lock_0

Without (working):
0000000000000000 A FMEX
00000000000013c0 T mexfunction_

____________________________
STRUCTURE OF MEX FUNCTION

! Type definitions for MATLAB mex files
#include "fintrf.h"

! MEX file gateway function
SUBROUTINE mexFunction(nlhs, plhs, nrhs, prhs)
USE weights_mod_pvr
IMPLICIT NONE

! DECLARE STUFF
! ALLOCATE VARIABLE SIZE ARRAYS DECLARED WITHIN THE MODULE
! COPY FROM INPUT POINTERS TO LOCAL VARIABLES

! Call a subroutine (defined within the module) to do some heavyweight processing
CALL reconstruct(ARGS)

! COPY FROM LOCAL VARIABLES TO OUTPUT POINTERS
! DEALLOCATE VARIABLE SIZE ARRAYS DECALRED WITHIN THE MODULE

RETURN
END SUBROUTINE mexFunction

____________________________
COMPILATION AND LINKING SCRIPT

# Set up name of mex file to compile
MEXNAME="mxmart_large_pvr_parallel"
MODNAME="weights_mod_pvr"
FORTEXT="F90"
MEXEXT="mexa64"

# Set up root directories
TMWROOT="/home/thc29/MATLAB/R2010b"

# Compilation Flags For Module
MODCOMPILEFLAGS="-c -O3 -fPIC -heap-arrays -fexceptions -xSSSE3 -parallel -guide -vec-report2 -par-report2"

# Compile Module
ifort $MODCOMPILEFLAGS $MODNAME"."$FORTEXT

# Compilation Flags For Mex Function
COMPILEFLAGS="-c -O3 -heap-arrays -fexceptions -ipo -fPIC -DMX_COMPAT_32 -xSSSE3 -DMATLAB_MEX_FILE"

# Linker Flags
LINKFLAGS=" -O3 -fPIC -shared -fno-omit-frame-pointer -DMATLAB_MEX_FILE -DMX_COMPAT_32 -static-intel -ipo -xSSSE3"

# Compile mex function
ifort $COMPILEFLAGS -I$TMWROOT/extern/include $MEXNAME.$FORTEXT

# Link (static intel with -fPIC)
ifort $LINKFLAGS -Wl,--version-script,$TMWROOT/extern/lib/glnxa64/fexport.map -Wl,--no-undefined -o $MEXNAME.$MEXEXT $MEXNAME.o $MODNAME.o /opt/intel/lib/intel64/libifcoremt_pic.a -Wl,-rpath-link,$TMWROOT/bin/glnxa64 -L$TMWROOT/bin/glnxa64 -lmx -lmex -lmat -lm -L/opt/intel/lib/intel64/ -liomp5

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.