Compile oct file with fortran openmp using LDFLAGS -
using ubuntu 14.04 octave 3.8.1. i'm attempting create .oct file makes use of multithreaded fortran program. however, mkoctfile fails use related libraries during linking.
the files i'm using follows: c:
#include <octave/oct.h> extern "c" { void fort5(); } defun_dld (ce5, args, ,"help here") { fort5(); }
fortran:
subroutine fort5() bind(c) use iso_c_binding implicit none !$omp parallel write(*,*) "hello" !$omp end parallel end subroutine fort5
i expect code result in output of 4 lines of "hello". compile following command mkoctfile cpp.cpp fortran.f90 result 1 output line, indicates multitrhreading ignored.
when compiled outside octave (with minor alterations c++ file) following command:
gcc -c cpp.cpp && gfortran -wall -fimplicit-none -wtabs -fdefault -real-8 -fopenmp -c fortran.f90 &&gfortran -fopenmp -o3 cpp.o fortran.o -lstdc++ -o out.out
the result should be.
from several tests becomes apparent, mkoctfile not capable use -fopenmp flag in form. found on internet should solvable using ldflags, however, reason fail @ that.
i set enviroment variable in octave terminal setenv("ldflags","-wl,-bsymbolic-functions, -wl,-z,relro, -fopenmp") setenv("fflags","-g -o2 -fstack-protector --param=ssp-buffer-size=4 -fopenmp") $mkoctfile --print ldflags indicates variable set successfully. however, compiled function fails load: $undefined symbol: gomp_parallel_start
i've tried explicitly listing library result same.
mkoctfile ce5.cpp fort5.o '-wl,-fopenmp' '-l /usr/lib/x86_64-linux-gnu/libgomp.so.1 mkoctfile ce5.cpp fort5.o '-wl,-fopenmp' '-l /usr/lib/x86_64-linux-gnu/'
did use flags correctly? else should correct compilation?
problem solved: seems consecutive application of following commands done trick:
setenv("fflags","-g -o2 -fstack-protector --param=ssp-buffer-size=4 -fopenmp") setenv("ldflags","-wl,-bsymbolic-functions, -wl,-z,relro, -wl,-fopenmp") mkoctfile ce5.cpp fort5.o '-l, /usr/lib/x86_64-linux-gnu/libgomp.so.1'
most problem setting correct flag compiler ($-fopenmp in fflags) , correct indication of library location.
Comments
Post a Comment