From: Yu-Chin Date: Fri, 25 Oct 2013 15:22:32 +0000 (+0800) Subject: . X-Git-Tag: v194~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4ba18c24e9dc9f526bd4b363aa0cc632e18a2b0b;p=liblinear . --- diff --git a/Makefile b/Makefile index 7a74e26..166308b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CXX ?= g++ CC ?= gcc -CFLAGS = -Wall -Wconversion -O3 -fPIC +CFLAGS = -Wall -Wconversion -O3 -fPIC -fopenmp LIBS = blas/blas.a SHVER = 1 OS = $(shell uname) diff --git a/linear.cpp b/linear.cpp index ca835ff..b7e1c88 100644 --- a/linear.cpp +++ b/linear.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "linear.h" #include "tron.h" typedef signed char schar; @@ -44,6 +46,8 @@ static void info(const char *fmt,...) static void info(const char *fmt,...) {} #endif +extern int nr_threads; + class l2r_lr_fun: public function { public: @@ -64,6 +68,8 @@ private: double *z; double *D; const problem *prob; + double **XTv_sub; + double *wa; }; l2r_lr_fun::l2r_lr_fun(const problem *prob, double *C) @@ -75,12 +81,19 @@ l2r_lr_fun::l2r_lr_fun(const problem *prob, double *C) z = new double[l]; D = new double[l]; this->C = C; + + XTv_sub = new double*[nr_threads]; + for(int ti=0;tin]; + + wa = new double[l]; } l2r_lr_fun::~l2r_lr_fun() { delete[] z; delete[] D; + delete[] wa; } @@ -97,6 +110,7 @@ double l2r_lr_fun::fun(double *w) for(i=0;il; int w_size=get_nr_variable(); +//#pragma omp parallel for private(i) for(i=0;il; int w_size=get_nr_variable(); - double *wa = new double[l]; + + for(i=0; il; feature_node **x=prob->x; +#pragma omp parallel for private(i) for(i=0;il; int w_size=get_nr_variable(); feature_node **x=prob->x; + for(int ti=0;tiindex!=-1) - { - XTv[s->index-1]+=v[i]*s->value; - s++; - } - } +#pragma omp parallel for private(i) + for(int ti=0; tiindex!=-1) + { + XTv_sub[ti][s->index-1]+=v[i]*s->value; + s++; + } + } + for(int ti=0; ti #include #include +#include +#include +#include #include "linear.h" #define Malloc(type,n) (type *)malloc((n)*sizeof(type)) #define INF HUGE_VAL @@ -92,6 +95,7 @@ struct model* model_; int flag_cross_validation; int nr_fold; double bias; +int nr_threads; int main(int argc, char **argv) { @@ -115,7 +119,12 @@ int main(int argc, char **argv) } else { + time_t start,end; + time(&start); model_=train(&prob, ¶m); + time(&end); + double diff = difftime(end,start); + printf("training time: %.2lf\n",diff); if(save_model(model_file_name, model_)) { fprintf(stderr,"can't save model to file %s\n",model_file_name); @@ -188,6 +197,7 @@ void parse_command_line(int argc, char **argv, char *input_file_name, char *mode param.weight = NULL; flag_cross_validation = 0; bias = -1; + nr_threads = 2; // parse options for(i=1;i