Skip to content

Commit

Permalink
If compilation fails with the -fopenmp flag, retry without the `-fo…
Browse files Browse the repository at this point in the history
…penmp` flag. Fixes #39 (#40)

* If compilation fails with -fopenmp flag, try again without that flag

* Add "deps/build.log" to .gitignore
  • Loading branch information
DilumAluthge authored and mpastell committed Jul 28, 2018
1 parent 2d8be89 commit ee10177
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.so.2
*.o
test*.jl

deps/build.log
32 changes: 27 additions & 5 deletions deps/libsvm-3.22/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
CXX ?= g++
CFLAGS = -Wall -Wconversion -O3 -fPIC -fopenmp
CFLAGS_normal = -Wall -Wconversion -O3 -fPIC -DENABLEOPENMP -fopenmp
CFLAGS_fallback = -Wall -Wconversion -O3 -DDISABLEOPENMP -fPIC
SHVER = 2
OS = $(shell uname)

all: svm-train svm-predict svm-scale

lib: svm.o
lib:
$(MAKE) lib_normal || $(MAKE) lib_fallback

lib_normal: svm.o
if [ "$(OS)" = "Darwin" ]; then \
SHARED_LIB_FLAG="-dynamiclib -Wl,-install_name,libsvm.so.$(SHVER)"; \
else \
SHARED_LIB_FLAG="-shared -Wl,-soname,libsvm.so.$(SHVER)"; \
fi; \
$(CXX) $${SHARED_LIB_FLAG} -DENABLEOPENMP -fopenmp svm.o -o libsvm.so.$(SHVER)

lib_fallback: svm.o
if [ "$(OS)" = "Darwin" ]; then \
SHARED_LIB_FLAG="-dynamiclib -Wl,-install_name,libsvm.so.$(SHVER)"; \
else \
SHARED_LIB_FLAG="-shared -Wl,-soname,libsvm.so.$(SHVER)"; \
fi; \
$(CXX) $${SHARED_LIB_FLAG} -fopenmp svm.o -o libsvm.so.$(SHVER)
$(CXX) $${SHARED_LIB_FLAG} -DDISABLEOPENMP svm.o -o libsvm.so.$(SHVER)

svm-predict: svm-predict.c svm.o
$(CXX) $(CFLAGS) svm-predict.c svm.o -o svm-predict -lm

svm-train: svm-train.c svm.o
$(CXX) $(CFLAGS) svm-train.c svm.o -o svm-train -lm

svm-scale: svm-scale.c
$(CXX) $(CFLAGS) svm-scale.c -o svm-scale
svm.o: svm.cpp svm.h
$(CXX) $(CFLAGS) -c svm.cpp

svm.o:
$(MAKE) svm.o_normal || $(MAKE) svm.o_fallback

svm.o_normal: svm.cpp svm.h
$(CXX) $(CFLAGS_normal) -c svm.cpp

svm.o_fallback: svm.cpp svm.h
$(CXX) $(CFLAGS_fallblack) -c svm.cpp

clean:
rm -f *~ svm.o svm-train svm-predict svm-scale libsvm.so.$(SHVER)
9 changes: 8 additions & 1 deletion deps/libsvm-3.22/svm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
#include <limits.h>
#include <locale.h>
#include "svm.h"
#include "omp.h"

#ifdef ENABLEOPENMP
#include "omp.h"
#else
#define omp_get_max_threads() 0
#define omp_set_num_threads(num_threads) void
#endif

int libsvm_version = LIBSVM_VERSION;
typedef float Qfloat;
typedef signed char schar;
Expand Down

0 comments on commit ee10177

Please sign in to comment.