final release of the multi threaded Crusher
This commit is contained in:
parent
bc6cb23d47
commit
f8764de7e1
12
BM1D.cc
12
BM1D.cc
|
@ -45,7 +45,7 @@ int main(int argc, char* argv[])
|
||||||
//todo fix parameters
|
//todo fix parameters
|
||||||
percent = 0.99;
|
percent = 0.99;
|
||||||
nGenerated = 7000;
|
nGenerated = 7000;
|
||||||
nop = 30;
|
nop = 43;
|
||||||
|
|
||||||
j_mu1=-25;
|
j_mu1=-25;
|
||||||
j_sigma1=0.3;
|
j_sigma1=0.3;
|
||||||
|
@ -71,8 +71,8 @@ int main(int argc, char* argv[])
|
||||||
rat=0.9;
|
rat=0.9;
|
||||||
|
|
||||||
percent = 0.99;
|
percent = 0.99;
|
||||||
nGenerated = 4000;
|
nGenerated = 8000;
|
||||||
nop = 30;
|
nop = 40;
|
||||||
|
|
||||||
vis = 1;
|
vis = 1;
|
||||||
typeOfRun = 1;
|
typeOfRun = 1;
|
||||||
|
@ -114,10 +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());
|
||||||
|
|
||||||
//int numCPU = sysconf(_SC_NPROCESSORS_ONLN);
|
int numCPU = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
//std::cout <<"cpus:"<<numCPU <<std::endl;
|
std::cout <<"cpus:"<<numCPU <<std::endl;
|
||||||
|
|
||||||
Draw2D *myDraw2D = new Draw2D(nop, percent, nGenerated, myBM1DProcess->GetT(), myBM1DProcess->GetX(),2); //nop percent nruns
|
Draw2D *myDraw2D = new Draw2D(nop, percent, nGenerated, myBM1DProcess->GetT(), myBM1DProcess->GetX(),numCPU); //nop percent nruns
|
||||||
|
|
||||||
switch(random_type){
|
switch(random_type){
|
||||||
case 'g' :
|
case 'g' :
|
||||||
|
|
|
@ -64,8 +64,8 @@ void Draw2D::Histo2D()
|
||||||
std::cout << "minMu:" << myLattice -> GetMuMin() << std::endl;
|
std::cout << "minMu:" << myLattice -> GetMuMin() << std::endl;
|
||||||
|
|
||||||
|
|
||||||
pthread_t thread[2];
|
pthread_t thread[nThreads];
|
||||||
Draw2DWorkerThread *worker[2];
|
Draw2DWorkerThread *worker[nThreads];
|
||||||
|
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
|
|
||||||
|
@ -74,16 +74,43 @@ void Draw2D::Histo2D()
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
void *status;
|
void *status;
|
||||||
|
|
||||||
|
|
||||||
|
int jobSize = myLattice -> GetLatticeSize();
|
||||||
|
if(nThreads <= 0 || jobSize <= 0)
|
||||||
|
{
|
||||||
|
std::cout<<"nThreads >= 1!!"<<std::endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(jobSize <= nThreads || nThreads > 32) //small jobb size or too large nThreads? -> run single thread mode
|
||||||
|
{
|
||||||
|
std::cout<<"strange jobSize or nThread number!! run single thread mode!!"<<std::endl;
|
||||||
|
worker[0] = new Draw2DWorkerThread(0, jobSize, x, t, nRuns, myLattice, BM1D_histo, BM1D_histo2, graphArray, &histoMutex);
|
||||||
|
nThreads = 1;
|
||||||
|
}
|
||||||
|
else //normal multi thread run
|
||||||
|
{
|
||||||
|
std::cout<<"Crusher run on "<< nThreads <<"thread"<<std::endl;
|
||||||
|
int jobSliceSize = jobSize / nThreads;
|
||||||
|
|
||||||
|
for(int i=0; i<nThreads; i++)
|
||||||
|
{
|
||||||
|
if(i == (nThreads - 1)) //larger slice
|
||||||
|
{
|
||||||
|
worker[i] = new Draw2DWorkerThread(jobSliceSize * i, (jobSize - (jobSliceSize * i)), x, t, nRuns, myLattice, BM1D_histo, BM1D_histo2, graphArray, &histoMutex);
|
||||||
|
}
|
||||||
|
else // normal slices
|
||||||
|
{
|
||||||
|
worker[i] = new Draw2DWorkerThread(jobSliceSize * i, jobSliceSize, x, t, nRuns, myLattice, BM1D_histo, BM1D_histo2, graphArray, &histoMutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
|
||||||
for(int i=0; i<2; i++)
|
for(int i=0; i<nThreads; i++)
|
||||||
{
|
{
|
||||||
std::cout<<"creating thread:"<<i<<std::endl;
|
std::cout<<"creating thread:"<<i<<std::endl;
|
||||||
rc = pthread_create(&thread[i], &attr, (THREADFUNCPTR) &Draw2DWorkerThread::WorkerFunction, (void *)worker[i]);
|
rc = pthread_create(&thread[i], &attr, (THREADFUNCPTR) &Draw2DWorkerThread::WorkerFunction, (void *)worker[i]);
|
||||||
|
@ -96,7 +123,7 @@ void Draw2D::Histo2D()
|
||||||
|
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
for(int i=0; i<2; i++)
|
for(int i=0; i<nThreads; i++)
|
||||||
{
|
{
|
||||||
rc = pthread_join(thread[i], &status);
|
rc = pthread_join(thread[i], &status);
|
||||||
if (rc)
|
if (rc)
|
||||||
|
@ -106,6 +133,11 @@ void Draw2D::Histo2D()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<nThreads; i++)
|
||||||
|
{
|
||||||
|
delete worker[i];
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "RunMachine done" << std::endl;
|
std::cout << "RunMachine done" << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue