early release of the multi threaded Crusher and minor fixes
This commit is contained in:
parent
a4ef471926
commit
bc6cb23d47
7
BM1D.cc
7
BM1D.cc
|
@ -71,7 +71,7 @@ int main(int argc, char* argv[])
|
||||||
rat=0.9;
|
rat=0.9;
|
||||||
|
|
||||||
percent = 0.99;
|
percent = 0.99;
|
||||||
nGenerated = 8000;
|
nGenerated = 4000;
|
||||||
nop = 30;
|
nop = 30;
|
||||||
|
|
||||||
vis = 1;
|
vis = 1;
|
||||||
|
@ -114,7 +114,10 @@ int main(int argc, char* argv[])
|
||||||
Plotter* myPlotter = new Plotter(vis==1);
|
Plotter* myPlotter = new Plotter(vis==1);
|
||||||
myPlotter->Plot(nRuns, nSteps, myBM1DProcess->GetT(), myBM1DProcess->GetX());
|
myPlotter->Plot(nRuns, nSteps, myBM1DProcess->GetT(), myBM1DProcess->GetX());
|
||||||
|
|
||||||
Draw2D *myDraw2D = new Draw2D(nop, percent, nGenerated, myBM1DProcess->GetT(), myBM1DProcess->GetX()); //nop percent nruns
|
//int numCPU = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
//std::cout <<"cpus:"<<numCPU <<std::endl;
|
||||||
|
|
||||||
|
Draw2D *myDraw2D = new Draw2D(nop, percent, nGenerated, myBM1DProcess->GetT(), myBM1DProcess->GetX(),2); //nop percent nruns
|
||||||
|
|
||||||
switch(random_type){
|
switch(random_type){
|
||||||
case 'g' :
|
case 'g' :
|
||||||
|
|
2
BM1D.cc_
2
BM1D.cc_
|
@ -39,7 +39,7 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
//default runs with less parameters
|
//default runs with less parameters
|
||||||
random_type = 'g';
|
random_type = 'g';
|
||||||
nSteps = 1000;
|
nSteps = 100;
|
||||||
nRuns = 1;
|
nRuns = 1;
|
||||||
p0 = 0.5;
|
p0 = 0.5;
|
||||||
p1 = 0;
|
p1 = 0;
|
||||||
|
|
|
@ -6,21 +6,27 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
||||||
#include "Analyse.hh"
|
#include "Analyse.hh"
|
||||||
#include "Lattice.hh"
|
#include "Lattice.hh"
|
||||||
#include "Crusher.hh"
|
#include "Crusher.hh"
|
||||||
#include "Plotter.hh"
|
#include "Plotter.hh"
|
||||||
|
#include "Draw2DWorkerThread.hh"
|
||||||
|
|
||||||
#include "TH2.h"
|
#include "TH2.h"
|
||||||
#include "TCanvas.h"
|
#include "TCanvas.h"
|
||||||
#include "TGraph.h"
|
#include "TGraph.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Draw2D
|
class Draw2D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Draw2D(int nop, double percent, int nRunsp, std::vector<Double_t> tp, std::vector<Double_t> xp);
|
Draw2D(int nop, double percent, int nRunsp, std::vector<Double_t> tp, std::vector<Double_t> xp, int nThreads_);
|
||||||
~Draw2D();
|
~Draw2D();
|
||||||
|
|
||||||
void Histo2D();
|
void Histo2D();
|
||||||
|
@ -30,6 +36,8 @@ class Draw2D
|
||||||
std::vector<Double_t> x;
|
std::vector<Double_t> x;
|
||||||
int nRuns;
|
int nRuns;
|
||||||
|
|
||||||
|
int nThreads;
|
||||||
|
|
||||||
Analyse *myAnalyse;
|
Analyse *myAnalyse;
|
||||||
Crusher *myCrusher;
|
Crusher *myCrusher;
|
||||||
Lattice *myLattice;
|
Lattice *myLattice;
|
||||||
|
@ -39,5 +47,7 @@ class Draw2D
|
||||||
TH2D *BM1D_histo2;
|
TH2D *BM1D_histo2;
|
||||||
TGraph *gr;
|
TGraph *gr;
|
||||||
|
|
||||||
|
struct graphArray graphArray;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
|
@ -0,0 +1,71 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <cmath>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "Lattice.hh"
|
||||||
|
#include "Crusher.hh"
|
||||||
|
|
||||||
|
#include "TH2.h"
|
||||||
|
#include "TCanvas.h"
|
||||||
|
#include "TGraph.h"
|
||||||
|
|
||||||
|
typedef void * (*THREADFUNCPTR)(void *);
|
||||||
|
|
||||||
|
struct graphArray
|
||||||
|
{
|
||||||
|
double *X;
|
||||||
|
double *Y;
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Draw2DWorkerThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Draw2DWorkerThread(int jobOffset_, int jobSize_, std::vector<Double_t> x_, std::vector<Double_t> t_, int nRuns_, Lattice *myLattice_, TH2D *BM1D_histo_, TH2D *BM1D_histo2_, struct graphArray graphArray_, pthread_mutex_t *histoMutex_);
|
||||||
|
|
||||||
|
~Draw2DWorkerThread();
|
||||||
|
|
||||||
|
void WorkerFunction();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
//output histo pointers
|
||||||
|
TH2D *BM1D_histo;
|
||||||
|
TH2D *BM1D_histo2;
|
||||||
|
|
||||||
|
//lattice instance pointer
|
||||||
|
Lattice *myLattice;
|
||||||
|
|
||||||
|
int nRuns; //Chrusher parameter number of tested "kukac"
|
||||||
|
|
||||||
|
std::vector<Double_t> t; //original "kukac"
|
||||||
|
std::vector<Double_t> x;
|
||||||
|
|
||||||
|
Crusher *myCrusher;
|
||||||
|
|
||||||
|
pthread_mutex_t *histoMutex;
|
||||||
|
|
||||||
|
//lattice parameters
|
||||||
|
double XbinSize;
|
||||||
|
double YbinSize;
|
||||||
|
double XbinSizePer2;
|
||||||
|
double YbinSizePer2;
|
||||||
|
int latticeHeight;
|
||||||
|
int latticeWidth;
|
||||||
|
double latticeMuMin;
|
||||||
|
double latticeSigmaMin;
|
||||||
|
|
||||||
|
int jobOffset;
|
||||||
|
int jobSize;
|
||||||
|
|
||||||
|
struct graphArray graphArray;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
|
@ -1,17 +1,17 @@
|
||||||
#include "Draw2D.hh"
|
#include "Draw2D.hh"
|
||||||
|
|
||||||
Draw2D::Draw2D(int nop, double percent, int nRunsp, std::vector<Double_t> tp, std::vector<Double_t> xp) //int nop, double percent, int nRunsp, std::vector<Double_t> tp, std::vector<Double_t> xp
|
|
||||||
|
Draw2D::Draw2D(int nop, double percent, int nRunsp, std::vector<Double_t> tp, std::vector<Double_t> xp, int nThreads_) //int nop, double percent, int nRunsp, std::vector<Double_t> tp, std::vector<Double_t> xp
|
||||||
{
|
{
|
||||||
t = tp;
|
t = tp;
|
||||||
x = xp;
|
x = xp;
|
||||||
nRuns = nRunsp;
|
nRuns = nRunsp;
|
||||||
|
|
||||||
|
nThreads = nThreads_;
|
||||||
|
|
||||||
myAnalyse = new Analyse();
|
myAnalyse = new Analyse();
|
||||||
myAnalyse -> AnalyseGaus(t,x);
|
myAnalyse -> AnalyseGaus(t,x);
|
||||||
|
|
||||||
myCrusher = new Crusher(t,x);
|
|
||||||
|
|
||||||
myLattice = new Lattice();
|
myLattice = new Lattice();
|
||||||
|
|
||||||
myLattice -> SetNop(nop);
|
myLattice -> SetNop(nop);
|
||||||
|
@ -25,7 +25,12 @@ Draw2D::Draw2D(int nop, double percent, int nRunsp, std::vector<Double_t> tp, st
|
||||||
|
|
||||||
BM1D_histo = new TH2D("BM1D_histo", "BM1D_histo", myLattice -> GetWidth() , myLattice -> GetMuMin(), (myLattice -> GetMuMax()) , myLattice -> GetHeight() , myLattice -> GetSigmaMin(), (myLattice -> GetSigmaMax()) );
|
BM1D_histo = new TH2D("BM1D_histo", "BM1D_histo", myLattice -> GetWidth() , myLattice -> GetMuMin(), (myLattice -> GetMuMax()) , myLattice -> GetHeight() , myLattice -> GetSigmaMin(), (myLattice -> GetSigmaMax()) );
|
||||||
BM1D_histo2 = new TH2D("BM1D_histo2", "BM1D_histo2", myLattice -> GetWidth() , myLattice -> GetMuMin(), (myLattice -> GetMuMax()) , myLattice -> GetHeight() , myLattice -> GetSigmaMin(), (myLattice -> GetSigmaMax()) );
|
BM1D_histo2 = new TH2D("BM1D_histo2", "BM1D_histo2", myLattice -> GetWidth() , myLattice -> GetMuMin(), (myLattice -> GetMuMax()) , myLattice -> GetHeight() , myLattice -> GetSigmaMin(), (myLattice -> GetSigmaMax()) );
|
||||||
gr = new TGraph();
|
|
||||||
|
graphArray.size = myLattice -> GetLatticeSize();
|
||||||
|
graphArray.X = new double[graphArray.size];
|
||||||
|
graphArray.Y = new double[graphArray.size];
|
||||||
|
|
||||||
|
gr = new TGraph(graphArray.size);
|
||||||
|
|
||||||
delete myAnalyse;
|
delete myAnalyse;
|
||||||
}
|
}
|
||||||
|
@ -44,47 +49,69 @@ Draw2D::~Draw2D()
|
||||||
delete gr;
|
delete gr;
|
||||||
|
|
||||||
delete myLattice;
|
delete myLattice;
|
||||||
delete myCrusher;
|
|
||||||
|
delete[] graphArray.X;
|
||||||
|
delete[] graphArray.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Draw2D::Histo2D()
|
void Draw2D::Histo2D()
|
||||||
{
|
{
|
||||||
double XbinSize = (myLattice -> GetMuMax() - myLattice -> GetMuMin())/ myLattice -> GetWidth() ;
|
|
||||||
double YbinSize =( myLattice -> GetSigmaMax() - myLattice -> GetSigmaMin() ) / myLattice -> GetHeight();
|
|
||||||
|
|
||||||
double graphArrayX[myLattice -> GetLatticeSize()] = {};
|
|
||||||
double graphArrayY[myLattice -> GetLatticeSize()] = {};
|
|
||||||
|
|
||||||
std::cout << "maxSigma:" << myLattice -> GetSigmaMax() << std::endl;
|
std::cout << "maxSigma:" << myLattice -> GetSigmaMax() << std::endl;
|
||||||
std::cout << "maxMu:" << myLattice -> GetMuMax() << std::endl;
|
std::cout << "maxMu:" << myLattice -> GetMuMax() << std::endl;
|
||||||
std::cout << "minSigma:" << myLattice -> GetSigmaMin() << std::endl;
|
std::cout << "minSigma:" << myLattice -> GetSigmaMin() << std::endl;
|
||||||
std::cout << "minMu:" << myLattice -> GetMuMin() << std::endl;
|
std::cout << "minMu:" << myLattice -> GetMuMin() << std::endl;
|
||||||
|
|
||||||
for(int i = 0; i < (myLattice -> GetLatticeSize()); i++)
|
|
||||||
{
|
|
||||||
std::cout<<"progress: "<<i<<"/"<<myLattice -> GetLatticeSize()<<"point\n";
|
|
||||||
|
|
||||||
if(myCrusher -> RunMachine(nRuns, myLattice -> GetMuSigma(i)))
|
|
||||||
{
|
|
||||||
BM1D_histo -> Fill((i / myLattice -> GetHeight()) * XbinSize + (XbinSize/2) + myLattice -> GetMuMin(),(i % myLattice -> GetHeight()) * YbinSize + (YbinSize/2) + myLattice -> GetSigmaMin() );
|
|
||||||
BM1D_histo2 -> Fill((i / myLattice -> GetHeight()) * XbinSize + (XbinSize/2) + myLattice -> GetMuMin(),(i % myLattice -> GetHeight()) * YbinSize + (YbinSize/2) + myLattice -> GetSigmaMin());
|
|
||||||
|
|
||||||
graphArrayX[i] = (i / myLattice -> GetHeight()) * XbinSize;
|
|
||||||
graphArrayY[i] = (i % myLattice -> GetHeight()) * YbinSize;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
pthread_t thread[2];
|
||||||
|
Draw2DWorkerThread *worker[2];
|
||||||
|
|
||||||
|
pthread_attr_t attr;
|
||||||
|
|
||||||
|
pthread_mutex_t histoMutex;
|
||||||
|
pthread_mutex_init(&histoMutex, NULL);
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
void *status;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
worker[0] = new Draw2DWorkerThread(0, (myLattice -> GetLatticeSize()/2), x, t, nRuns, myLattice, BM1D_histo, BM1D_histo2, graphArray, &histoMutex);
|
||||||
|
worker[1] = new Draw2DWorkerThread((myLattice -> GetLatticeSize()/2), (myLattice -> GetLatticeSize()/2), x, t, nRuns, myLattice, BM1D_histo, BM1D_histo2, graphArray, &histoMutex);
|
||||||
|
|
||||||
|
pthread_attr_init(&attr);
|
||||||
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
|
||||||
|
for(int i=0; i<2; i++)
|
||||||
|
{
|
||||||
|
std::cout<<"creating thread:"<<i<<std::endl;
|
||||||
|
rc = pthread_create(&thread[i], &attr, (THREADFUNCPTR) &Draw2DWorkerThread::WorkerFunction, (void *)worker[i]);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
std::cout<<"ERROR; pthread:"<<i<<"create failed!"<<std::endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
|
for(int i=0; i<2; i++)
|
||||||
|
{
|
||||||
|
rc = pthread_join(thread[i], &status);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
std::cout<<"ERROR; pthread:"<<i<<"join failed!"<<std::endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "RunMachine done" << std::endl;
|
std::cout << "RunMachine done" << std::endl;
|
||||||
|
|
||||||
//TGraph *gr = new TGraph(myLattice -> GetLatticeSize(),graphArrayX,graphArrayY);
|
|
||||||
|
|
||||||
gr -> SetMarkerColor(46);
|
gr -> SetMarkerColor(46);
|
||||||
canvasB2 -> cd();
|
canvasB2 -> cd();
|
||||||
//gr -> LineStyle()
|
gr -> DrawGraph(graphArray.size, graphArray.X, graphArray.Y, "AP*");
|
||||||
gr -> DrawGraph(myLattice -> GetLatticeSize(),graphArrayX,graphArrayY,"AP*");
|
|
||||||
|
|
||||||
BM1D_histo -> SetMarkerStyle(kFullCircle);
|
BM1D_histo -> SetMarkerStyle(kFullCircle);
|
||||||
BM1D_histo-> SetMarkerStyle(21);
|
BM1D_histo-> SetMarkerStyle(21);
|
||||||
|
@ -94,5 +121,6 @@ void Draw2D::Histo2D()
|
||||||
canvasB -> cd(2);
|
canvasB -> cd(2);
|
||||||
BM1D_histo2 -> Draw("COLZ");
|
BM1D_histo2 -> Draw("COLZ");
|
||||||
|
|
||||||
std::cout << "Histo done" << std::endl;
|
std::cout << "Histo draw done" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
#include "Draw2DWorkerThread.hh"
|
||||||
|
|
||||||
|
Draw2DWorkerThread::Draw2DWorkerThread(int jobOffset_, int jobSize_, std::vector<Double_t> x_, std::vector<Double_t> t_, int nRuns_, Lattice *myLattice_, TH2D *BM1D_histo_, TH2D *BM1D_histo2_, struct graphArray graphArray_, pthread_mutex_t *histoMutex_)
|
||||||
|
{
|
||||||
|
std::cout << "Draw2DWorkerThread::Draw2DWorkerThread" <<std::endl;
|
||||||
|
//copy to private variables
|
||||||
|
x = x_;
|
||||||
|
t = t_;
|
||||||
|
|
||||||
|
myLattice = myLattice_;
|
||||||
|
|
||||||
|
BM1D_histo = BM1D_histo_;
|
||||||
|
BM1D_histo2 =BM1D_histo2_;
|
||||||
|
graphArray = graphArray_;
|
||||||
|
|
||||||
|
nRuns = nRuns_;
|
||||||
|
|
||||||
|
histoMutex = histoMutex_;
|
||||||
|
|
||||||
|
jobOffset = jobOffset_;
|
||||||
|
jobSize = jobSize_;
|
||||||
|
|
||||||
|
//create Crusher instance
|
||||||
|
myCrusher = new Crusher(t,x);
|
||||||
|
|
||||||
|
//calculate lattice parameters TODO rework lattice class!!
|
||||||
|
XbinSize = (myLattice -> GetMuMax() - myLattice -> GetMuMin())/ myLattice -> GetWidth() ;
|
||||||
|
YbinSize =( myLattice -> GetSigmaMax() - myLattice -> GetSigmaMin() ) / myLattice -> GetHeight();
|
||||||
|
XbinSizePer2 = XbinSize/2;
|
||||||
|
YbinSizePer2 = YbinSize/2;
|
||||||
|
latticeHeight = myLattice -> GetHeight();
|
||||||
|
latticeWidth = myLattice -> GetWidth();
|
||||||
|
latticeMuMin = myLattice -> GetMuMin();
|
||||||
|
latticeSigmaMin = myLattice -> GetSigmaMin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Draw2DWorkerThread::~Draw2DWorkerThread()
|
||||||
|
{
|
||||||
|
delete myCrusher;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Draw2DWorkerThread::WorkerFunction()
|
||||||
|
{
|
||||||
|
std::cout << "Draw2DWorkerThread::WorkerFunction" <<std::endl;
|
||||||
|
std::cout << "jobOffset:"<< jobOffset<< "jobSize:" << jobSize <<std::endl;
|
||||||
|
for(int i = jobOffset; i < (jobOffset + jobSize); i++)
|
||||||
|
{
|
||||||
|
std::cout<<"progress: "<<i<<"/"<<myLattice -> GetLatticeSize()<<"point\n";
|
||||||
|
|
||||||
|
if(myCrusher -> RunMachine(nRuns, myLattice -> GetMuSigma(i)))
|
||||||
|
{
|
||||||
|
pthread_mutex_lock (histoMutex); //fill histo thread safe???
|
||||||
|
|
||||||
|
BM1D_histo ->Fill((i / latticeHeight) * XbinSize + XbinSizePer2 + latticeMuMin, (i % latticeHeight) * YbinSize + YbinSizePer2 + latticeSigmaMin );
|
||||||
|
BM1D_histo2 ->Fill((i / latticeHeight) * XbinSize + XbinSizePer2 + latticeMuMin, (i % latticeHeight) * YbinSize + YbinSizePer2 + latticeSigmaMin );
|
||||||
|
|
||||||
|
graphArray.X[i] = (i / latticeHeight) * XbinSize;
|
||||||
|
graphArray.Y[i] = (i % latticeHeight)* YbinSize;
|
||||||
|
|
||||||
|
pthread_mutex_unlock (histoMutex);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pthread_exit((void*) 0); //kell?? vagy NULL??
|
||||||
|
}
|
|
@ -105,7 +105,7 @@ void Lattice::SetLattice(Double_t mu_est, Double_t sigma_est){
|
||||||
ms_vect[i].mu = loc_mu;
|
ms_vect[i].mu = loc_mu;
|
||||||
ms_vect[i].sigma = loc_sigma;
|
ms_vect[i].sigma = loc_sigma;
|
||||||
|
|
||||||
std::cout << "i : " << ms_vect[i].mu << " " << ms_vect[i].sigma << std::endl;
|
//std::cout << "i : " << ms_vect[i].mu << " " << ms_vect[i].sigma << std::endl;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
loc_sigma += ds;
|
loc_sigma += ds;
|
||||||
|
|
Loading…
Reference in New Issue