Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 360157 - sci-libs/libsvm-3.0 should use multithreading
Summary: sci-libs/libsvm-3.0 should use multithreading
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Gentoo Science Related Packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-23 15:21 UTC by Roby
Modified: 2011-08-09 04:47 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
OpenMP patch for LibSVM-3.1 (libsvm-3.1-omp.patch,1.50 KB, patch)
2011-04-25 22:14 UTC, Roby
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roby 2011-03-23 15:21:51 UTC
Multithreading can be enabled for libsvm-3.0, though it requires some modification in the source and the makefile. However, the modification is trivial and is explained here:
http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#f432

The dependency required is OpenMP and GCC >= 4.2. Description (in case the webpage above is down):

It is very easy if you are using GCC 4.2 or after.

In Makefile, add -fopenmp to CFLAGS.

In class SVC_Q of svm.cpp, modify the for loop of get_Q to:

#pragma omp parallel for private(j) 
			for(j=start;j<len;j++)

In the subroutine svm_predict_values of svm.cpp, add one line to the for loop:

#pragma omp parallel for private(i) 
		for(i=0;i<l;i++)
			kvalue[i] = Kernel::k_function(x,model->SV[i],model->param);

For regression, you need a reduction clause for the variable sum:

#pragma omp parallel for private(i) reduction(+:sum) 
		for(i=0;i<model->l;i++)
			sum += sv_coef[i] * Kernel::k_function(x,model>SV[i],model>param);

Then rebuild the package. Kernel evaluations in training/testing will be parallelized.

...

For Python interface, you need to add the -lgomp link option:

$(CXX) -lgomp -shared -dynamiclib svm.o -o libsvm.so.$(SHVER)


Reproducible: Always
Comment 1 Sébastien Fabbro (RETIRED) gentoo-dev 2011-03-30 20:24:28 UTC
Hi. That could be a nice improvement, but we have the policy to follow upstream as much as we can. You could suggest the libsvm folks to roll a new release with the possibility of enabling openmp.
Or if you insist, provide a patch here for the current ebuild. Also note gomp is specific to gcc.

Thanks.
Comment 2 Roby 2011-04-25 22:14:39 UTC
Created attachment 271171 [details, diff]
OpenMP patch for LibSVM-3.1

Patch to enable OpenMP for LibSVM-3.1.
Comment 3 Roby 2011-04-25 22:18:07 UTC
Okay. I've created a patch for LibSVM version 3.1 (which is still not available in Portage tree at the time of this writing). Basically, we need to build LibSVM with "make OPENMP=y" instead of simply "make".

The problem is I don't know much about ebuild files. So, I don't know how to modify it. Hope this helps.
Comment 4 Sébastien Fabbro (RETIRED) gentoo-dev 2011-08-09 04:47:46 UTC
in cvs. thanks!