Hello!
I want to increase the speed of my programm.
Fiting is the most hard CPU process.
I know, that there is PROOF system, but I am a noob and it is difficult for me to understand this system quickly.
I have tried to use OpenMP for my task.
I use VS2013 and root_v5.34.32 on windows7.
You can see the simple example below.
Main.cpp
#include <iostream>
#include <vector>
#include <omp.h>
#include "TRandom.h"
#include "TMath.h"
#include "TGraphErrors.h"
#include "TF1.h"
#include "Math/MinimizerOptions.h"
#include "MyClass.h"
using namespace std;
int main()
{
int i;
#pragma omp parallel private(i)
{
#pragma omp for schedule (static)
for (int i = 0; i < 8; i++)
{
MyClass *obj = new MyClass();
obj->SetParameters();
obj->DoFit();
}
}
system("pause");
return 0;
}
MyClass.h
#pragma once
#include <vector>
#include "TRandom.h"
#include "TMath.h"
#include "TGraphErrors.h"
#include "TF1.h"
#include "Math/MinimizerOptions.h"
using namespace std;
class MyClass
{
public:
MyClass();
~MyClass();
void DoFit();
void SetParameters();
private:
vector<double> xv;
vector<double> yv;
vector<double> xverr;
vector<double> yverr;
static TF1 *fitFcn;
static Double_t fitFunction(Double_t *x, Double_t *par);
TGraphErrors * gr;
};
MyClass.cpp
#include "MyClass.h"
TF1 *MyClass::fitFcn;
MyClass::MyClass()
{
fitFcn = new TF1("fitFcn", MyClass::fitFunction, -10, 20, 3);
const double noise_amp = 300;
//fill vectors ...
for (int i = -10; i < 20; i++)
{
xv.push_back(i);
yv.push_back((pow((i - 3.5) * 5, 2.0) + 3) + noise_amp*gRandom->Uniform(-1, 1));
xverr.push_back(0);
yverr.push_back(noise_amp);
}
gr = new TGraphErrors(xv.size(), &xv[0], &yv[0], &xverr[0], &yverr[0]);
gr->SetMarkerColor(4);
gr->SetMarkerStyle(kFullCircle);
}
MyClass::~MyClass()
{
}
Double_t MyClass::fitFunction(Double_t *x, Double_t *par)
{
return pow((x[0] - par[2])*par[0], 2.0) + par[1];
}
void MyClass::SetParameters()
{
//set statr parameters and limits
fitFcn->SetParameter(0, 1);
fitFcn->SetParLimits(0, 0, 10);
fitFcn->SetParameter(1, 1);
fitFcn->SetParLimits(1, -100, 100);
fitFcn->SetParameter(2, 1);
fitFcn->SetParLimits(2, -10, 10);
}
void MyClass::DoFit()
{
gr->Fit("fitFcn", "R");
}
If I use more than one thread I have error:
Warning in <ROOT::Math::FitConfig::CreateMinimizer>: Could not create the Minuit minimizer. Try using the minimizer Minuit2
Error in <ROOT::Math::FitConfig::CreateMinimizer>: Could not create the Minuit2 minimizer
Error in <ROOT::Math::Fitter::FitFCN>: Minimizer cannot be created
Warning in <Fit>: Abnormal termination of minimization
This error appears when gr->Fit(“fitFcn”, “R”); line is being doing.
Could you help me to overcome this error?
Or could you give me simplest way in order to parallelize this programm?
Yours sincerely, Vladislav.