Matlab 2014a mex build fail with Openmp
3 次查看(过去 30 天)
显示 更早的评论
Hi, I'm having some issues building a mex file using Matlab coder (project interface) in R2014a on a new machine. The function I'm building is an m file that performs (computationally heavy) Monte Carlo simulations in parallel using a parfor loop. If I replace it with a simple for loop, then everything compiles just fine. But I'm taking a pretty massive runtime hit as the workstation I'm using has 11/12 logical cores that are not being used.
It builds just fine on a separate Windows 8 PC with a VS compiler, and also on a colleague's Ubuntu 12.04 station with gcc 4.7 installed and Matlab R2013b.
At first I thought maybe it was due to the fact that the Ubuntu version I'm using (14.04) comes with gcc 4.8 as default, so I changed installed and changed the default system compilers to gcc/g++ 4.7, and modified the ~/MATLAB/R2014a/bin/mexopts.sh file to select those compilers as well. But still no luck.
I've been searching online for a fix for quite a while, but I'm making little headway. Any tips about how to proceed would be greatly appreciated!
By the way, these are the build errors I get, taken directly from the coder error report logs 33 OBFB_finite_mem_sim_initialize.o: In function `OBFB_finite_mem_sim_initialize': 34 OBFB_finite_mem_sim_initialize.c:(.text+0x34): undefined reference to `omp_get_num_procs' 35 OBFB_finite_mem_sim_terminate.o: In function `OBFB_finite_mem_sim_atexit': 36 OBFB_finite_mem_sim_terminate.c:(.text+0x22): undefined reference to `omp_get_num_procs' 37 OBFB_finite_mem_sim.o: In function `OBFB_finite_mem_sim._omp_fn.1': 38 OBFB_finite_mem_sim.c:(.text+0x516): undefined reference to `omp_get_num_threads' 39 OBFB_finite_mem_sim.c:(.text+0x51d): undefined reference to `omp_get_thread_num' 40 OBFB_finite_mem_sim.c:(.text+0x4942): undefined reference to `omp_get_thread_num' 41 OBFB_finite_mem_sim.o: In function `getThreadID_init._omp_fn.0': 42 OBFB_finite_mem_sim.c:(.text+0x5155): undefined reference to `omp_get_num_threads' 43 OBFB_finite_mem_sim.c:(.text+0x515c): undefined reference to `omp_get_thread_num' 44 OBFB_finite_mem_sim.c:(.text+0x521c): undefined reference to `GOMP_barrier' 45 OBFB_finite_mem_sim.c:(.text+0x5243): undefined reference to `omp_get_thread_num' 46 OBFB_finite_mem_sim.o: In function `OBFB_finite_mem_sim': 47 OBFB_finite_mem_sim.c:(.text+0xde28): undefined reference to `omp_in_parallel' 48 OBFB_finite_mem_sim.c:(.text+0xde4f): undefined reference to `omp_in_parallel' 49 OBFB_finite_mem_sim.c:(.text+0xde8d): undefined reference to `omp_get_num_procs' 50 OBFB_finite_mem_sim.c:(.text+0xde94): undefined reference to `omp_get_max_threads' 51 OBFB_finite_mem_sim.c:(.text+0xde9c): undefined reference to `omp_in_parallel' 52 OBFB_finite_mem_sim.c:(.text+0xe0da): undefined reference to `GOMP_parallel_start' 53 OBFB_finite_mem_sim.c:(.text+0xe0eb): undefined reference to `GOMP_parallel_end' 54 OBFB_finite_mem_sim.c:(.text+0xe199): undefined reference to `omp_in_parallel' 55 OBFB_finite_mem_sim.c:(.text+0xe1ea): undefined reference to `omp_in_parallel' 56 OBFB_finite_mem_sim.o: In function `getThreadID_init': 57 OBFB_finite_mem_sim.c:(.text+0xffae): undefined reference to `omp_get_max_threads' 58 OBFB_finite_mem_sim.c:(.text+0xffb6): undefined reference to `omp_in_parallel' 59 OBFB_finite_mem_sim.c:(.text+0xffd2): undefined reference to `omp_get_num_procs' 60 OBFB_finite_mem_sim.c:(.text+0xffda): undefined reference to `omp_get_max_threads' 61 OBFB_finite_mem_sim.c:(.text+0xffe2): undefined reference to `omp_in_parallel' 62 OBFB_finite_mem_sim.c:(.text+0x1001a): undefined reference to `GOMP_parallel_start' 63 OBFB_finite_mem_sim.c:(.text+0x10028): undefined reference to `GOMP_parallel_end' 64 OBFB_finite_mem_sim.c:(.text+0x1003d): undefined reference to `omp_in_parallel' 65 eml_rand.o: In function `eml_rand_init._omp_fn.0': 66 eml_rand.c:(.text+0x6a): undefined reference to `omp_get_num_threads' 67 eml_rand.c:(.text+0x71): undefined reference to `omp_get_thread_num' 68 eml_rand.c:(.text+0x120): undefined reference to `GOMP_barrier' 69 eml_rand.c:(.text+0x145): undefined reference to `omp_get_thread_num' 70 eml_rand.o: In function `eml_rand_init': 71 eml_rand.c:(.text+0x26f): undefined reference to `omp_get_max_threads' 72 eml_rand.c:(.text+0x277): undefined reference to `omp_in_parallel' 73 eml_rand.c:(.text+0x293): undefined reference to `omp_get_num_procs' 74 eml_rand.c:(.text+0x29b): undefined reference to `omp_get_max_threads' 75 eml_rand.c:(.text+0x2a3): undefined reference to `omp_in_parallel' 76 eml_rand.c:(.text+0x2db): undefined reference to `GOMP_parallel_start' 77 eml_rand.c:(.text+0x2e9): undefined reference to `GOMP_parallel_end' 78 eml_rand.c:(.text+0x2fe): undefined reference to `omp_in_parallel' 79 eml_rand_mt19937ar_stateful.o: In function `c_eml_rand_mt19937ar_stateful_i._omp_fn.0': 80 eml_rand_mt19937ar_stateful.c:(.text+0x32d): undefined reference to `omp_get_num_threads' 81 eml_rand_mt19937ar_stateful.c:(.text+0x334): undefined reference to `omp_get_thread_num' 82 eml_rand_mt19937ar_stateful.c:(.text+0x3ea): undefined reference to `GOMP_barrier' 83 eml_rand_mt19937ar_stateful.c:(.text+0x411): undefined reference to `omp_get_thread_num' 84 eml_rand_mt19937ar_stateful.o: In function `c_eml_rand_mt19937ar_stateful_i': 85 eml_rand_mt19937ar_stateful.c:(.text+0x91b): undefined reference to `omp_get_max_threads' 86 eml_rand_mt19937ar_stateful.c:(.text+0x923): undefined reference to `omp_in_parallel' 87 eml_rand_mt19937ar_stateful.c:(.text+0x93f): undefined reference to `omp_get_num_procs' 88 eml_rand_mt19937ar_stateful.c:(.text+0x947): undefined reference to `omp_get_max_threads' 89 eml_rand_mt19937ar_stateful.c:(.text+0x94f): undefined reference to `omp_in_parallel' 90 eml_rand_mt19937ar_stateful.c:(.text+0x987): undefined reference to `GOMP_parallel_start' 91 eml_rand_mt19937ar_stateful.c:(.text+0x995): undefined reference to `GOMP_parallel_end' 92 eml_rand_mt19937ar_stateful.c:(.text+0x9aa): undefined reference to `omp_in_parallel' 93 eml_randn.o: In function `eml_randn_init._omp_fn.0': 94 eml_randn.c:(.text+0x6a): undefined reference to `omp_get_num_threads' 95 eml_randn.c:(.text+0x71): undefined reference to `omp_get_thread_num' 96 eml_randn.c:(.text+0x148): undefined reference to `GOMP_barrier' 97 eml_randn.c:(.text+0x171): undefined reference to `omp_get_thread_num' 98 eml_randn.o: In function `eml_randn_init': 99 eml_randn.c:(.text+0x248): undefined reference to `omp_get_max_threads' 100 eml_randn.c:(.text+0x250): undefined reference to `omp_in_parallel' 101 eml_randn.c:(.text+0x26c): undefined reference to `omp_get_num_procs' 102 eml_randn.c:(.text+0x274): undefined reference to `omp_get_max_threads' 103 eml_randn.c:(.text+0x27c): undefined reference to `omp_in_parallel' 104 eml_randn.c:(.text+0x2b4): undefined reference to `GOMP_parallel_start' 105 eml_randn.c:(.text+0x2c2): undefined reference to `GOMP_parallel_end' 106 eml_randn.c:(.text+0x2d7): undefined reference to `omp_in_parallel' 107 _coder_OBFB_finite_mem_sim_mex.o: In function `OBFB_finite_mem_sim_mexFunction': 108 _coder_OBFB_finite_mem_sim_mex.c:(.text+0x16b): undefined reference to `omp_destroy_lock' 109 _coder_OBFB_finite_mem_sim_mex.c:(.text+0x177): undefined reference to `omp_destroy_nest_lock' 110 _coder_OBFB_finite_mem_sim_mex.o: In function `mexFunction': 111 _coder_OBFB_finite_mem_sim_mex.c:(.text+0x209): undefined reference to `omp_init_lock' 112 _coder_OBFB_finite_mem_sim_mex.c:(.text+0x215): undefined reference to `omp_init_nest_lock' 113 _coder_OBFB_finite_mem_sim_mex.c:(.text+0x246): undefined reference to `omp_destroy_lock' 114 _coder_OBFB_finite_mem_sim_mex.c:(.text+0x252): undefined reference to `omp_destroy_nest_lock' 115 _coder_OBFB_finite_mem_sim_mex.o: In function `emlrtLockerFunction': 116 _coder_OBFB_finite_mem_sim_mex.c:(.text+0x298): undefined reference to `omp_set_lock' 117 _coder_OBFB_finite_mem_sim_mex.c:(.text+0x2a9): undefined reference to `omp_unset_lock' 118 collect2: error: ld returned 1 exit status 119 gmake: * [OBFB_finite_mem_sim_mex.mexa64] Error 1
0 个评论
采纳的回答
Ryan Livingston
2014-8-18
There is an apparent difference on Ubuntu with linking OpenMP where the flag -fopenmp needs to be manually added to the build options. To do this at the command line you can:
cfg = coder.config('mex');
cfg.PostCodeGenCommand = 'buildInfo.addLinkFlags(''-fopenmp'')';
codegen -config cfg <YourFunction>
Or from the user interface set "Settings->Custom Code->Post-code-generation command" to:
buildInfo.addLinkFlags(''-fopenmp'')
This will manually add in the linker flag that says to include OpenMP.
3 个评论
Ryan Livingston
2014-8-19
编辑:Ryan Livingston
2014-8-19
There is a bug report covering one workaround for this error:
As with any installation modification, I would recommend backing up the files to be changed before applying it.
If that doesn't work for you, it may be best to contact Technical Support:
as they can help narrow down other workarounds.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!