Skip to content

Instantly share code, notes, and snippets.

@alfard
Created April 10, 2013 16:02
Show Gist options
  • Select an option

  • Save alfard/5355969 to your computer and use it in GitHub Desktop.

Select an option

Save alfard/5355969 to your computer and use it in GitHub Desktop.
Armadillo
#include <iostream>
#define ARMA_NO_DEBUG
#include <armadillo>
#include <ctime>
#include <thread>
using namespace std;
using namespace arma;
mat X;
mat Result(156849,1);
mat Result3(156849,1);
mat End;
mat Endi;
////////////////////////////////////////////////////////////////
void task1() {
X.load("e4.csv",auto_detect);
mat Y2;
Y2.load("comparaisonY2.csv",auto_detect);
mat ensemblefity2(156849,1);
mat T;
for( int j = 0; j < 156850; j++ )
{
ensemblefity2=exp((Y2.col(0)*X(j,0)+Y2.col(1)*X(j,1)+Y2.col(2)*X(j,2)+Y2.col(3)*X(j,3))/100)-1;
T = join_rows(Y2,ensemblefity2);
Result(j,0)= sqrt(sum(square( log( T.col(5) +1 )- log( T.col(4)+1 )))/Y2.n_rows);
cout << j << endl;
}
}
////////////////////////////////////////////////////////////////
//g++ Endmulti.cpp -o multi -O2 -larmadillo -std=c++0x -lpthread
void task2() {
X.load("e4.csv",auto_detect);
mat Y3;
Y3.load("comparaisonY3.csv",auto_detect);
mat ensemblefity3(156849,1);
mat T3;
for( int i = 0; i < 156850; i++ )
{
ensemblefity3=exp((Y3.col(0)*X(i,0)+Y3.col(1)*X(i,1)+Y3.col(2)*X(i,2)+Y3.col(3)*X(i,3))/100)-1;
T3 = join_rows(Y3,ensemblefity3);
Result3(i,0)= sqrt(sum(square( log( T3.col(5) +1 )- log( T3.col(4)+1 )))/Y3.n_rows);
}
}
int main()
{
thread thread_1 = thread(task1);
thread thread_2 = thread(task2);
time_t tstart, tend;
tstart = time(0);
/////////////////////////////////////////////////////////////
thread_2.join();
thread_1.join();
Endi=join_rows(Result,Result3);
End=join_rows(X,Endi);
End.save("End.csv",csv_ascii);
tend = time(0);
cout << "It took "<< difftime(tend, tstart) <<" second(s)."<< endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment