Background:
I have some Matlab functions that I have implemented in C++ for my Master Thesis, and I want to try using the PGI 14.1 compiler with OpenACC to GPU-accelerate an extensive for-loop in the C++ MEX function. During the last week I have bin doing several attempts to make the unsuportet (by Matlab at least) link between PGI and MATLAB work. I have tried on Windows 7 (32bit), MAC OS X 10.9 (x86_64) and Scientific Linux 6 (x86_64). Using MATLAB 2013b for Unix, and 2013a on Windows.
All my functions is compiling fine with GCC 4.8 and 4.9 (the ones I have used earlier).
To make Matlab call PGI, a lot of tweeking has to be done in the mexopts file, and I have been doing some of this for all tree arcitectures (here is a nice guide for win64: Walking Randomly » Using the Portland PGI Compiler for MATLAB mex files in Windows #1 ). The Unix mexopts.sh file that I have adapted can be found here: http://folk.ntnu.no/seljasen/Arbeider/PGI_mexopts.sh . The most simple C++ MEX function I have been using is a C++ implementation of Matlabs normalized sinc() function for which the source code can be seen here: http://folk.ntnu.no/seljasen/Arbeider/MEX_sinc.cpp . This MEX function features OpenMP, but it compiles fine using GCC both with or without the GCC -fopenmp flag (i know this is -mp for the PGI compiler, but I am new with the whole PGI compiler bundle).
Problem:
Om both Windows and Linux the problem seems to boil down to the linking with system libraries that reqires the entry point “main” which in a MEX-function is renamed: “mexFunction”. This gives a vaiaty of different “missing entry point” errors. I have been googling for days, and it does not seem to bee very common to try and make PGI and MATLAB become friends. On some forums there is stated that I need the GCC switch “-bundle” on Unix, but this switch is not recogniced by PGI. Does there exist an equvivalent? In Windows the same gcc switch seems to be “-Mmakedll=export_all”, which also is ignored on my PGI compiler.
I do not need to compile the file on all tree platforms, but I need it on one of them to work. Preferably Linux or Windows. The object file is made without errors or warnings so this seem to be a linking problem.
Does anyone have any clue?
Tell me if you want more details.
A typical windows and Linux error msg is:
LINK : fatal error LNK1561: entry point must be defined
On MAC i suspect there are som apple issues as well, or immaturity in my adaptet mexopts function because there I get the following error:
Undefined symbols for architecture x86_64:
"__div__Q2_3std16complex__tm__2_dSFRCdN31RdT5", referenced from:
_mexFunction in openMP_sinc_source.o
___CPR79____dv__tm__2_d__3stdFRCQ2_3std18complex__tm__4_Z1ZT1_Q2_3stdJ29J in openMP_sinc_source.o
"_main", referenced from:
__start in crt1.o
"_sin__3stdFRCQ2_3std16complex__tm__2_d", referenced from:
_mexFunction in openMP_sinc_source.o
ld: symbol(s) not found for inferred architecture x86_64
mex: link of ' "openMP_sinc_source.mexmaci64"' failed.
But it is not my focus to get this working on MAC, as the computational servers I am working on uses Linux or Windows.
Thank you in advance!