TMatrix for large matrices

Dear rooters,

I am trying to perform matrix calculations, in order to compute covariance matrices but this requires big matrices (maybe in the order of 50000). I started playing with TMatrix to do so, and so far I have the following code

#include <iostream>
#include <fstream>
#include <vector>
#include "TROOT.h"
#include "TGraph.h"
#include "TH1.h"
#include "TMath.h"
#include "TMatrixF.h"
#include "TMatrixFSym.h"
#include "TMatrixTSym.h"
#include "TString.h"
#include "TRandom.h"
#include "covariance_lib.cc"

using namespace std;

int covariance_linear_interpolation(TString filename){
// (1) Free-Up memory
	gROOT->Reset();
// (2) Define the isolethargic binning - MeV
	int 	E_MAX = 1, E_MIN = -11, N_BPDEC = 1000;
	int 	ndec  = E_MAX - E_MIN;
	int 	nbins = (int) ndec*N_BPDEC;
	float	step = (float) ndec / nbins;
	float	En_USER[nbins+1];

	for(int i=0; i <= nbins; i++) {
		En_USER[i] = (float) pow(10., step * (float) i + E_MIN);
	}

// (3) Read the evaluation and interpolate
	int nbins_EVAL = count_lines(filename);
	float xs_USER[nbins+1], En_EVAL[nbins_EVAL], xs_EVAL[nbins_EVAL];
	int   idx[nbins+1];
	input_ascii(filename, En_EVAL, xs_EVAL);	
	linear_interpolation(nbins, nbins_EVAL, En_USER, xs_USER, En_EVAL, xs_EVAL, idx);
// (2) Define the size for the covariance matrices
	const int size_EVAL = nbins_EVAL;
	const int size_USER = nbins;
// (3) Define the types of T-objects that will be used
	float covariance_EVAL[size_EVAL*(size_EVAL+1)/2];
	for (int i=0; i<size_EVAL*(size_EVAL+1)/2; ++i){
		covariance_EVAL[i] = gRandom->Gaus(0.1, 5);
	}
	TMatrixFSym COV_EVAL(size_EVAL, covariance_EVAL);
	//
	//COV_EVAL.Print();
	
	
/*
// (5) Get the evaluated cross section and store it in a graph
	float En_EVAL[size_EVAL], xs_EVAL[size_EVAL];
	for (int i=0; i<size_EVAL; ++i){
		En_EVAL[i] = i+1;
		xs_EVAL[i] = cos(i);
	}
	TGraph *g_XS_EVAL = new TGraph(size_EVAL, En_EVAL, xs_EVAL);
	g_XS_EVAL->Draw("APL");
	
// (6) Calculate the interpolated cross section and it in a TGraph as well
	float En_USER[size_USER], xs_USER[size_USER], idx[size_USER];
	//for (int i=0; i<size_USER; ++i){
	//	En_USER[i]  = 1.2*(i+1);
	//	xs_USER[i] = g_XS_EVAL->Eval(En_USER[i]);
	//}
	TGraph *g_XS_USER = new TGraph(size_USER, En_USER, xs_USER);
	g_XS_USER->SetLineColor(kBlue); g_XS_USER->Draw("PLsame");

// (6) Define the sensitivity matrix and fill it
	SMatrixStd_USERxEVAL	G;
	
	for (int i=0; i<size_USER; ++i){
		for (int j=0; j<size_EVAL; ++j){
			G(i,j) = pow(0.02, i)*j+i/100;
		}
	}
// (7) Calculate the covariance matrix - will be symmetric
	SMatrixStd_USER V_USER;
	V_USER = G*V*Transpose(G);
	
// (8) Print the matrices for checking	
	std::cout << V << std::endl;
	std::cout << "**************************************************************************\n";
	std::cout << G << std::endl;
	std::cout << "**************************************************************************\n";
	std::cout << V_USER << std::endl;
*/	
	return 0;

}

The covariance_lib.cc follows

// Inputs :  	-name   = name of the ascii file to be read - two column file with x and y values, rescpectively assumed
//		-X_USER = array that contains the user defined energy binning
//		-output = if output = TRUE  exports the interpolation array
//			  if output = FALSE exports the index of the input values used in the interpolation
void linear_interpolation(int size_USER, int size_EVAL, float* X_USER, float* Y_USER, float* X_EVAL, float* Y_EVAL, int* index){

	float x1, x2,y1, y2, a, b;
	bool  boo;
	x1 = 0.; x2 = 0.; y1 = 0; y2 = 0.; a  = 0.; b  = 0.;
    	for(int i=0; i<=size_USER; ++i){
		boo = true;
		for (int j=0; j<=size_EVAL; j++){
			if (boo==true){
				if(X_USER[i] == X_EVAL[j]){
					Y_USER[i] = Y_EVAL[j];
					index[i]  = j;
					boo = false;
				}
				else if(X_USER[i]>X_EVAL[j]){
					x1 = X_EVAL[j];
					y1 = Y_EVAL[j];
					index[i] = j;
				}
				else if( X_USER[i]<X_EVAL[j] && boo == true ){
					x2 = X_EVAL[j];
					y2 = Y_EVAL[j];
					a = (y2-y1)/(x2-x1);
					b = y2-a*x2;
					Y_USER[i] = a*X_USER[i]+b;
					//index[i]  = j;
					boo = false;
				}
			}
		}//end of loop over EVAL
	}//end of loop over USER	
}//____linear_interpolation()


void input_ascii(TString filename, float* X_EVAL, float* Y_EVAL){

	ifstream myfile;
	myfile.open(filename);
	float x = 0, y = 0;
	int   i = 0;
  	while(1){
		myfile >> x >> y;
		if (!myfile.good()) break;
		X_EVAL[i]    = x;
		Y_EVAL[i]    = y;
		i++;
	}
    	myfile.close();
}//___input_ascii()


int count_lines(TString filename){

	float	x, y;
	int nlines;	
	// (1) Open the file to count its lines
	ifstream myfile;
	myfile.open(filename);
  	if(!myfile){
		cout << "File not found" << endl;
  	}
  	nlines = 0;
  	while(1){
  		myfile >> x >> y;
  		if (!myfile.good()) break;
		nlines++;
	}
	myfile.close();
	return nlines;

}//___count_lines()


std::vector<float> isolethargic_binning(int min, int max, int bpd){

	int 	ndec  = max - min;
	int 	nbins = (int) ndec*bpd;
	float	step = (float) ndec / nbins;
	std::vector<float> xbins(nbins+1);

	for(int i=0; i <= nbins; i++) {
		xbins[i] = (float) pow(10., step * (float) i + min);
	}
	
	return xbins;

}//___isolethargic_binning()

A sample file can be found here
For this sample file, I have to create a 20000 x 20000 symmetric matrix, but it seems that I am out of memory. So when I compile and run the code (note that I am running 5.32 on lxplus) using

root [0] .L covariance_linear-interpolation.C++
root [1] covariance_linear_interpolation("ENDF_B-VII_1.dat")

root automatically quits. I suppose that this is happening because the matrix must be big.

I also tried defining the array using

float *covariance_EVAL = new float[size_EVAL*(size_EVAL+1)/2];

and in this case the code is running for more time but ends up with a crash

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f444a16482e in waitpid () from /lib64/libc.so.6
#1  0x00007f444a0f6479 in do_system () from /lib64/libc.so.6
#2  0x00007f444ae07b04 in TUnixSystem::StackTrace() () from /usr/lib64/root/libCore.so.5.34
#3  0x00007f444ae06f23 in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib64/root/libCore.so.5.34
#4  <signal handler called>
#5  0x00007f444a141aaf in memcpy () from /lib64/libc.so.6
#6  0x00007f4446464dd0 in TMatrixTBase<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#7  0x00007f44464903b9 in TMatrixTSym<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#8  0x00007f4446491627 in TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) () from /usr/lib64/root/libMatrix.so
#9  0x00007f4442a4b1f6 in covariance_linear_interpolation (filename=<incomplete type>) at /eos/user/a/astamato/covariance/code/./covariance_linear-interpolation.C:47
#10 0x00007f4442a4b34d in G__covariance_linear_interpolation_C_ACLiC_dict__0_2358 (result7=0x7ffc958a0350, funcname=<value optimized out>, libp=<value optimized out>, hash=<value optimized out>) at /eos/user/a/astamato/covariance/code/covariance_linear_interpolation_C_ACLiC_dict.cxx:82
#11 0x00007f4449785ba9 in Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) () from /usr/lib64/root/libCint.so.5.34
#12 0x00007f444982ded1 in G__execute_call () from /usr/lib64/root/libCint.so.5.34
#13 0x00007f444982ed22 in G__call_cppfunc () from /usr/lib64/root/libCint.so.5.34
#14 0x00007f444980da05 in G__interpret_func () from /usr/lib64/root/libCint.so.5.34
#15 0x00007f44497fc918 in G__getfunction () from /usr/lib64/root/libCint.so.5.34
#16 0x00007f44497db12e in G__getitem () from /usr/lib64/root/libCint.so.5.34
#17 0x00007f44497dfcb8 in G__getexpr () from /usr/lib64/root/libCint.so.5.34
#18 0x00007f444985abe7 in G__exec_statement () from /usr/lib64/root/libCint.so.5.34
#19 0x00007f44497c72d1 in ?? () from /usr/lib64/root/libCint.so.5.34
#20 0x00007f44497c75de in G__exec_tempfile_fp () from /usr/lib64/root/libCint.so.5.34
#21 0x00007f4449866645 in G__process_cmd () from /usr/lib64/root/libCint.so.5.34
#22 0x00007f444adc7c46 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /usr/lib64/root/libCore.so.5.34
#23 0x00007f444ad2b0e0 in TApplication::ProcessLine(char const*, bool, int*) () from /usr/lib64/root/libCore.so.5.34
#24 0x00007f444a97a05b in TRint::HandleTermInput() () from /usr/lib64/root/libRint.so.5.34
#25 0x00007f444ae04f8e in TUnixSystem::CheckDescriptors() () from /usr/lib64/root/libCore.so.5.34
#26 0x00007f444ae05273 in TUnixSystem::DispatchOneEvent(bool) () from /usr/lib64/root/libCore.so.5.34
#27 0x00007f444ad85bd6 in TSystem::InnerLoop() () from /usr/lib64/root/libCore.so.5.34
#28 0x00007f444ad8770b in TSystem::Run() () from /usr/lib64/root/libCore.so.5.34
#29 0x00007f444ad282df in TApplication::Run(bool) () from /usr/lib64/root/libCore.so.5.34
#30 0x00007f444a97b5b4 in TRint::Run(bool) () from /usr/lib64/root/libRint.so.5.34
#31 0x000000000040103c in main ()
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007f444a141aaf in memcpy () from /lib64/libc.so.6
#6  0x00007f4446464dd0 in TMatrixTBase<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#7  0x00007f44464903b9 in TMatrixTSym<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#8  0x00007f4446491627 in TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) () from /usr/lib64/root/libMatrix.so
#9  0x00007f4442a4b1f6 in covariance_linear_interpolation (filename=<incomplete type>) at /eos/user/a/astamato/covariance/code/./covariance_linear-interpolation.C:47
===========================================================


Root > !!!Dictionary position not recovered because G__unloadfile() is used in a macro!!!

Any idea on how to see what’s happening and how to use TMatrix for big matrices?

Thanks in advance!

You are probably smashing your stack with this array, allocated on the stack (ie: 12000+1 floats):

use dynamic memory (ie: the heap) instead.

I changed the declaration of arrays using

float* name = new float[size];

My new code is now

//#include "/afs/cern.ch/user/a/astamato/public/lib_thanos/c_header.h"
//#include "/afs/cern.ch/user/a/astamato/public/lib_thanos/root_header.h"
#include <iostream>
#include <fstream>
#include <vector>
#include "TROOT.h"
#include "TGraph.h"
#include "TH1.h"
#include "TMath.h"
#include "TMatrixF.h"
#include "TMatrixFSym.h"
#include "TMatrixTSym.h"
#include "TString.h"
#include "TRandom.h"
#include "covariance_lib.cc"

using namespace std;

int covariance_linear_interpolation(TString filename){
// (1) Free-Up memory
	gROOT->Reset();
// (2) Define the isolethargic binning - MeV
	int 	E_MAX = 1, E_MIN = -11, N_BPDEC = 1000;
	int 	ndec  = E_MAX - E_MIN;
	int 	nbins = (int) ndec*N_BPDEC;
	float	step = (float) ndec / nbins;
	float*	En_USER = new float[nbins+1];

	for(int i=0; i <= nbins; i++) {
		En_USER[i] = (float) pow(10., step * (float) i + E_MIN);
	}

// (3) Read the evaluation and interpolate
	int nbins_EVAL = count_lines(filename);
	float* xs_USER = new float[nbins+1];
	float* En_EVAL = new float[nbins_EVAL];
	float* xs_EVAL = new float[nbins_EVAL];
	int*   idx     = new int[nbins+1];
	input_ascii(filename, En_EVAL, xs_EVAL);	
	linear_interpolation(nbins, nbins_EVAL, En_USER, xs_USER, En_EVAL, xs_EVAL, idx);
// (2) Define the size for the covariance matrices
	const int size_EVAL = nbins_EVAL;
	const int size_USER = nbins;
// (3) Define the types of T-objects that will be used
	float *covariance_EVAL = new float[size_EVAL*(size_EVAL+1)/2];
	for (int i=0; i<size_EVAL*(size_EVAL+1)/2; ++i){
		covariance_EVAL[i] = gRandom->Gaus(0.1, 5);
	}
	TMatrixFSym COV_EVAL(size_EVAL, covariance_EVAL);


// (6) Define the sensitivity matrix and fill it
	TMatrixF G(size_USER, size_EVAL);
	
	for (int i=0; i<size_USER; ++i){
		for (int j=0; j<size_EVAL; ++j){
			G(i,j) = pow(0.02, i)*j+i/100;
		}
	}
// (7) Calculate the covariance matrix - will be symmetric
	TMatrixF COV_USER = G*COV_EVAL*G.T();
	//COV_USER = G*COV_EVAL*G.T();
/*	
// (8) Print the matrices for checking	
	std::cout << V << std::endl;
	std::cout << "**************************************************************************\n";
	std::cout << G << std::endl;
	std::cout << "**************************************************************************\n";
	std::cout << V_USER << std::endl;
*/	
	return 0;

}

It compiles without problems (although it takes some time), but when trying to do the matrix multiplication I get the following after a while

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f871788982e in waitpid () from /lib64/libc.so.6
#1  0x00007f871781b479 in do_system () from /lib64/libc.so.6
#2  0x00007f871852cb04 in TUnixSystem::StackTrace() () from /usr/lib64/root/libCore.so.5.34
#3  0x00007f871852bf23 in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib64/root/libCore.so.5.34
#4  <signal handler called>
#5  0x00007f8717866aaf in memcpy () from /lib64/libc.so.6
#6  0x00007f8713b89dd0 in TMatrixTBase<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#7  0x00007f8713bb53b9 in TMatrixTSym<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#8  0x00007f8713bb6627 in TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) () from /usr/lib64/root/libMatrix.so
#9  0x00007f871016f55a in covariance_linear_interpolation (filename=<value optimized out>) at /eos/user/a/astamato/covariance/code/./covariance_linear-interpolation.C:49
#10 0x00007f871016f9ed in G__covariance_linear_interpolation_C_ACLiC_dict__0_2358 (result7=0x7ffe0bc696e0, funcname=<value optimized out>, libp=<value optimized out>, hash=<value optimized out>) at /eos/user/a/astamato/covariance/code/covariance_linear_interpolation_C_ACLiC_dict.cxx:82
#11 0x00007f8716eaaba9 in Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) () from /usr/lib64/root/libCint.so.5.34
#12 0x00007f8716f52ed1 in G__execute_call () from /usr/lib64/root/libCint.so.5.34
#13 0x00007f8716f53d22 in G__call_cppfunc () from /usr/lib64/root/libCint.so.5.34
#14 0x00007f8716f32a05 in G__interpret_func () from /usr/lib64/root/libCint.so.5.34
#15 0x00007f8716f21918 in G__getfunction () from /usr/lib64/root/libCint.so.5.34
#16 0x00007f8716f0012e in G__getitem () from /usr/lib64/root/libCint.so.5.34
#17 0x00007f8716f04cb8 in G__getexpr () from /usr/lib64/root/libCint.so.5.34
#18 0x00007f8716f7fbe7 in G__exec_statement () from /usr/lib64/root/libCint.so.5.34
#19 0x00007f8716eec2d1 in ?? () from /usr/lib64/root/libCint.so.5.34
#20 0x00007f8716eec5de in G__exec_tempfile_fp () from /usr/lib64/root/libCint.so.5.34
#21 0x00007f8716f8b645 in G__process_cmd () from /usr/lib64/root/libCint.so.5.34
#22 0x00007f87184ecc46 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /usr/lib64/root/libCore.so.5.34
#23 0x00007f87184500e0 in TApplication::ProcessLine(char const*, bool, int*) () from /usr/lib64/root/libCore.so.5.34
#24 0x00007f871809f05b in TRint::HandleTermInput() () from /usr/lib64/root/libRint.so.5.34
#25 0x00007f8718529f8e in TUnixSystem::CheckDescriptors() () from /usr/lib64/root/libCore.so.5.34
#26 0x00007f871852a273 in TUnixSystem::DispatchOneEvent(bool) () from /usr/lib64/root/libCore.so.5.34
#27 0x00007f87184aabd6 in TSystem::InnerLoop() () from /usr/lib64/root/libCore.so.5.34
#28 0x00007f87184ac70b in TSystem::Run() () from /usr/lib64/root/libCore.so.5.34
#29 0x00007f871844d2df in TApplication::Run(bool) () from /usr/lib64/root/libCore.so.5.34
#30 0x00007f87180a05b4 in TRint::Run(bool) () from /usr/lib64/root/libRint.so.5.34
#31 0x000000000040103c in main ()
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007f8717866aaf in memcpy () from /lib64/libc.so.6
#6  0x00007f8713b89dd0 in TMatrixTBase<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#7  0x00007f8713bb53b9 in TMatrixTSym<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#8  0x00007f8713bb6627 in TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) () from /usr/lib64/root/libMatrix.so
#9  0x00007f871016f55a in covariance_linear_interpolation (filename=<value optimized out>) at /eos/user/a/astamato/covariance/code/./covariance_linear-interpolation.C:49
===========================================================


Root > !!!Dictionary position not recovered because G__unloadfile() is used in a macro!!!

Note that if I remove the following lines

// (6) Define the sensitivity matrix and fill it
	TMatrixF G(size_USER, size_EVAL);
	
	for (int i=0; i<size_USER; ++i){
		for (int j=0; j<size_EVAL; ++j){
			G(i,j) = pow(0.02, i)*j+i/100;
		}
	}
// (7) Calculate the covariance matrix - will be symmetric
	TMatrixF COV_USER = G*COV_EVAL*G.T();

the code runs. I guess that still the memory is an issue, right?
Any advice on how to do the matrix multiplication?

I tried deleting the arrays after not needing them any more so as to free up some space using

delete[] name;

Additionally I used a TMatrixFSparse object because I thought it would occupy less memory space. So my newest version of the code is

#include <iostream>
#include <fstream>
#include <vector>
#include "TROOT.h"
#include "TGraph.h"
#include "TH1.h"
#include "TMath.h"
#include "TMatrixF.h"
#include "TMatrixFSym.h"
#include "TMatrixFSparse.h"
#include "TMatrixTSym.h"
#include "TString.h"
#include "TRandom.h"
#include "covariance_lib.cc"

using namespace std;

int covariance_linear_interpolation(TString filename){
// (1) Free-Up memory
	gROOT->Reset();
// (2) Define the isolethargic binning - MeV
	int 	E_MAX = 1, E_MIN = -11, N_BPDEC = 1000;
	int 	ndec  = E_MAX - E_MIN;
	int 	nbins = (int) ndec*N_BPDEC;
	float	step = (float) ndec / nbins;
	float*	En_USER = new float[nbins+1];

	for(int i=0; i <= nbins; i++) {
		En_USER[i] = (float) pow(10., step * (float) i + E_MIN);
	}

// (3) Read the evaluation and interpolate
	int nbins_EVAL = count_lines(filename);
	float* xs_USER = new float[nbins+1];
	float* En_EVAL = new float[nbins_EVAL];
	float* xs_EVAL = new float[nbins_EVAL];
	int*   idx     = new int[nbins+1];
	input_ascii(filename, En_EVAL, xs_EVAL);	
	linear_interpolation(nbins, nbins_EVAL, En_USER, xs_USER, En_EVAL, xs_EVAL, idx);
// (2) Define the size for the covariance matrices
	const int size_EVAL = nbins_EVAL;
	const int size_USER = nbins;
// (3) Define the types of T-objects that will be used
	float *covariance_EVAL = new float[size_EVAL*(size_EVAL+1)/2];
	for (int i=0; i<size_EVAL*(size_EVAL+1)/2; ++i){
		covariance_EVAL[i] = gRandom->Gaus(0.1, 5);
	}
	TMatrixFSym COV_EVAL(size_EVAL, covariance_EVAL);
	
	delete[] covariance_EVAL;
	delete[] xs_USER;
	delete[] xs_EVAL;
	

// () Define the non-zero elements of the SParse TMatrix
	int*   icol  = new int[2*(nbins+1)];
	int*   irow  = new int[2*(nbins+1)];
	float* coeff = new float[2*(nbins+1)];
	
	for (int i=0; i<(nbins+1); ++i){
		icol[2*i]    = idx[i];
		icol[2*i+1]  = idx[i]++;	
		irow[2*i]    = i;
		irow[2*i+1]  = i;
		coeff[2*i]   = 1 + (En_USER[i]-En_EVAL[idx[i]])/(En_EVAL[idx[i]]-En_EVAL[idx[i+1]]);
		coeff[2*i+1] = coeff[2*i] - 1;	
	}
	
	
	TMatrixFSparse G(size_USER, size_EVAL);
	G.SetMatrixArray(2*(nbins+1), irow, icol, coeff);

But still it can’t run. The output when running is

root [11] covariance_linear_interpolation("ENDF_B-VII_1.dat")

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f159877582e in waitpid () from /lib64/libc.so.6
#1  0x00007f1598707479 in do_system () from /lib64/libc.so.6
#2  0x00007f1599418b04 in TUnixSystem::StackTrace() () from /usr/lib64/root/libCore.so.5.34
#3  0x00007f1599417f23 in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib64/root/libCore.so.5.34
#4  <signal handler called>
#5  0x00007f1598752aaf in memcpy () from /lib64/libc.so.6
#6  0x00007f1594a75dd0 in TMatrixTBase<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#7  0x00007f1594aa13b9 in TMatrixTSym<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#8  0x00007f1594aa2627 in TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) () from /usr/lib64/root/libMatrix.so
#9  0x00007f14c0eb49d2 in covariance_linear_interpolation (filename=<incomplete type>) at /eos/user/a/astamato/covariance/code/./covariance_linear-interpolation.C:50
#10 0x00007f14c0eb4cad in G__covariance_linear_interpolation_C_ACLiC_dict__0_2358 (result7=0x7fff5b8504e0, funcname=<value optimized out>, libp=<value optimized out>, hash=<value optimized out>) at /eos/user/a/astamato/covariance/code/covariance_linear_interpolation_C_ACLiC_dict.cxx:82
#11 0x00007f1597d96ba9 in Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) () from /usr/lib64/root/libCint.so.5.34
#12 0x00007f1597e3eed1 in G__execute_call () from /usr/lib64/root/libCint.so.5.34
#13 0x00007f1597e3fd22 in G__call_cppfunc () from /usr/lib64/root/libCint.so.5.34
#14 0x00007f1597e1ea05 in G__interpret_func () from /usr/lib64/root/libCint.so.5.34
#15 0x00007f1597e0d918 in G__getfunction () from /usr/lib64/root/libCint.so.5.34
#16 0x00007f1597dec12e in G__getitem () from /usr/lib64/root/libCint.so.5.34
#17 0x00007f1597df0cb8 in G__getexpr () from /usr/lib64/root/libCint.so.5.34
#18 0x00007f1597e6bbe7 in G__exec_statement () from /usr/lib64/root/libCint.so.5.34
#19 0x00007f1597dd82d1 in ?? () from /usr/lib64/root/libCint.so.5.34
#20 0x00007f1597dd85de in G__exec_tempfile_fp () from /usr/lib64/root/libCint.so.5.34
#21 0x00007f1597e77645 in G__process_cmd () from /usr/lib64/root/libCint.so.5.34
#22 0x00007f15993d8c46 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /usr/lib64/root/libCore.so.5.34
#23 0x00007f159933c0e0 in TApplication::ProcessLine(char const*, bool, int*) () from /usr/lib64/root/libCore.so.5.34
#24 0x00007f1598f8b05b in TRint::HandleTermInput() () from /usr/lib64/root/libRint.so.5.34
#25 0x00007f1599415f8e in TUnixSystem::CheckDescriptors() () from /usr/lib64/root/libCore.so.5.34
#26 0x00007f1599416273 in TUnixSystem::DispatchOneEvent(bool) () from /usr/lib64/root/libCore.so.5.34
#27 0x00007f1599396bd6 in TSystem::InnerLoop() () from /usr/lib64/root/libCore.so.5.34
#28 0x00007f159939870b in TSystem::Run() () from /usr/lib64/root/libCore.so.5.34
#29 0x00007f15993392df in TApplication::Run(bool) () from /usr/lib64/root/libCore.so.5.34
#30 0x00007f1598f8c5b4 in TRint::Run(bool) () from /usr/lib64/root/libRint.so.5.34
#31 0x000000000040103c in main ()
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007f1598752aaf in memcpy () from /lib64/libc.so.6
#6  0x00007f1594a75dd0 in TMatrixTBase<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#7  0x00007f1594aa13b9 in TMatrixTSym<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#8  0x00007f1594aa2627 in TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) () from /usr/lib64/root/libMatrix.so
#9  0x00007f14c0eb49d2 in covariance_linear_interpolation (filename=<incomplete type>) at /eos/user/a/astamato/covariance/code/./covariance_linear-interpolation.C:50
===========================================================

Any idea on how to proceed?
Thanks in advance!

Never call this from within a function, it might remove information about the function itself and/or its callers.

In addition you seem to be using v5. Cint had trouble with the litetime of object on the stack (likely to be kept allocated longer that you would expect).

I recommend updating to ROOT v6.12 or if this is not an option to compile your code with ACLiC.

Cheers,
Philippe.

Oh! I didn’t know about gROOT->Reset(). Thanks a lot!

I am indeed using v5 on lxplus. I might move to v6.12 if it’s better.
But how can I compile using ACLiC?

TROOT::Reset

ROOT 5.x User’s Guide -> CINT the C++ Interpreter -> ACLiC - The Automatic Compiler of Libraries for CINT

ROOT 6.x User’s Guide -> The C++ Interpreter Cling -> ACLiC: Compiling Scripts Into Libraries

1 Like

Thanks a lot for the references!

So I think that I am already using ACLiC since I do the following

root [0] .L covariance_linear_interpolation.C++

So if this is the case, then I might need another workaround to play with big matrices.

To see if there is a problem try to run with valgrind

valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp root.exe -b -l 
root [] .L covariance_linear_interpolation.C+
root [] ...

And if that is clean you call try with --tool==massif

Cheers,
Philippe.

I noticed a strange behaviour…
When running the code for the first time, I get this error

root [25] covariance_linear_interpolation("ENDF_B-VII_1.dat", 0)

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007ff10626a82e in waitpid () from /lib64/libc.so.6
#1  0x00007ff1061fc479 in do_system () from /lib64/libc.so.6
#2  0x00007ff106f0db04 in TUnixSystem::StackTrace() () from /usr/lib64/root/libCore.so.5.34
#3  0x00007ff106f0cf23 in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib64/root/libCore.so.5.34
#4  <signal handler called>
#5  0x00007ff106247aaf in memcpy () from /lib64/libc.so.6
#6  0x00007ff10256add0 in TMatrixTBase<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#7  0x00007ff1025963b9 in TMatrixTSym<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#8  0x00007ff102597627 in TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) () from /usr/lib64/root/libMatrix.so
#9  0x00007fef5e7ffbd4 in covariance_linear_interpolation (filename=<incomplete type>, return_TMatrix=<value optimized out>) at /eos/user/a/astamato/covariance/code/./covariance_linear-interpolation.C:51
#10 0x00007fef5e800150 in G__covariance_linear_interpolation_C_ACLiC_dict__0_2358 (result7=0x7ffc216813b0, funcname=<value optimized out>, libp=<value optimized out>, hash=<value optimized out>) at /eos/user/a/astamato/covariance/code/covariance_linear_interpolation_C_ACLiC_dict.cxx:82
#11 0x00007ff10588bba9 in Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) () from /usr/lib64/root/libCint.so.5.34
#12 0x00007ff105933ed1 in G__execute_call () from /usr/lib64/root/libCint.so.5.34
#13 0x00007ff105934d22 in G__call_cppfunc () from /usr/lib64/root/libCint.so.5.34
#14 0x00007ff105913a05 in G__interpret_func () from /usr/lib64/root/libCint.so.5.34
#15 0x00007ff105902918 in G__getfunction () from /usr/lib64/root/libCint.so.5.34
#16 0x00007ff1058e112e in G__getitem () from /usr/lib64/root/libCint.so.5.34
#17 0x00007ff1058e5cb8 in G__getexpr () from /usr/lib64/root/libCint.so.5.34
#18 0x00007ff105960be7 in G__exec_statement () from /usr/lib64/root/libCint.so.5.34
#19 0x00007ff1058cd2d1 in ?? () from /usr/lib64/root/libCint.so.5.34
#20 0x00007ff1058cd5de in G__exec_tempfile_fp () from /usr/lib64/root/libCint.so.5.34
#21 0x00007ff10596c645 in G__process_cmd () from /usr/lib64/root/libCint.so.5.34
#22 0x00007ff106ecdc46 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /usr/lib64/root/libCore.so.5.34
#23 0x00007ff106e310e0 in TApplication::ProcessLine(char const*, bool, int*) () from /usr/lib64/root/libCore.so.5.34
#24 0x00007ff106a8005b in TRint::HandleTermInput() () from /usr/lib64/root/libRint.so.5.34
#25 0x00007ff106f0af8e in TUnixSystem::CheckDescriptors() () from /usr/lib64/root/libCore.so.5.34
#26 0x00007ff106f0b273 in TUnixSystem::DispatchOneEvent(bool) () from /usr/lib64/root/libCore.so.5.34
#27 0x00007ff106e8bbd6 in TSystem::InnerLoop() () from /usr/lib64/root/libCore.so.5.34
#28 0x00007ff106e8d70b in TSystem::Run() () from /usr/lib64/root/libCore.so.5.34
#29 0x00007ff106e2e2df in TApplication::Run(bool) () from /usr/lib64/root/libCore.so.5.34
#30 0x00007ff106a815b4 in TRint::Run(bool) () from /usr/lib64/root/libRint.so.5.34
#31 0x000000000040103c in main ()
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007ff106247aaf in memcpy () from /lib64/libc.so.6
#6  0x00007ff10256add0 in TMatrixTBase<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#7  0x00007ff1025963b9 in TMatrixTSym<float>::SetMatrixArray(float const*, char const*) () from /usr/lib64/root/libMatrix.so
#8  0x00007ff102597627 in TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) () from /usr/lib64/root/libMatrix.so
#9  0x00007fef5e7ffbd4 in covariance_linear_interpolation (filename=<incomplete type>, return_TMatrix=<value optimized out>) at /eos/user/a/astamato/covariance/code/./covariance_linear-interpolation.C:51
===========================================================


Root >

When executing it again it seems that is running. So it’s strange because in even executions it crashes, but in odd it runs!

Any idea?

My new code is the following

//#include "/afs/cern.ch/user/a/astamato/public/lib_thanos/c_header.h"
//#include "/afs/cern.ch/user/a/astamato/public/lib_thanos/root_header.h"
#include <iostream>
#include <fstream>
#include <vector>
#include "TROOT.h"
#include "TGraph.h"
#include "TH1.h"
#include "TMath.h"
#include "TMatrixF.h"
#include "TMatrixFSym.h"
#include "TMatrixFSparse.h"
#include "TMatrixTSym.h"
#include "TString.h"
#include "TRandom.h"
#include "covariance_lib.cc"

using namespace std;

void covariance_linear_interpolation(TString filename, bool return_TMatrix){
// (2) Define the isolethargic binning - MeV
	int 	E_MAX = 1, E_MIN = -11, N_BPDEC = 1000;
	int 	ndec  = E_MAX - E_MIN;
	int 	nbins = (int) ndec*N_BPDEC;
	float	step  = (float) ndec / nbins;
	float*	En_USER = new float[nbins];

	for(int i=0; i <= nbins; i++) {
		En_USER[i] = (float) pow(10., step * (float) i + E_MIN);
	}

// (3) Read the evaluation and interpolate
	int nbins_EVAL = count_lines(filename);
	float* xs_USER = new float[nbins];
	float* En_EVAL = new float[nbins_EVAL];
	float* xs_EVAL = new float[nbins_EVAL];
	int*   idx     = new int[nbins];
	input_ascii(filename, En_EVAL, xs_EVAL);	
	linear_interpolation(nbins, nbins_EVAL, En_USER, xs_USER, En_EVAL, xs_EVAL, idx);

// (2) Define the size for the covariance matrices
	const int size_EVAL = nbins_EVAL;
	const int size_USER = nbins;
	
// (3) Define the types of T-objects that will be used
	float *covariance_EVAL = new float[size_EVAL*(size_EVAL+1)/2];
	for (int i=0; i<size_EVAL*(size_EVAL+1)/2; ++i){
		covariance_EVAL[i] = gRandom->Gaus(0.1, 5);
	}
	//TMatrixFSym *COV_EVAL = new TMatrixFSym(size_EVAL, covariance_EVAL);
	TMatrixFSym COV_EVAL(size_EVAL, covariance_EVAL);
	
	delete[] covariance_EVAL;
	delete[] xs_USER;
	delete[] xs_EVAL;

// () Define the non-zero elements of the SParse TMatrix
	int*   icol  = new int[2*(nbins)];
	int*   irow  = new int[2*(nbins)];
	float* coeff = new float[2*(nbins)];
	
	for (int i=0; i<(nbins); ++i){
		icol[2*i]    = idx[i];
		icol[2*i+1]  = idx[i] + 1;	
		irow[2*i]    = i;
		irow[2*i+1]  = i;
		coeff[2*i]   = 1 + (En_USER[i]-En_EVAL[idx[i]])/(En_EVAL[idx[i]]-En_EVAL[idx[i+1]]);
		coeff[2*i+1] = coeff[2*i] - 1;
	}
	
	delete[] En_USER;
	delete[] En_EVAL;
	delete[] idx;
	
	TMatrixFSparse G(size_USER, size_EVAL);
	G.SetMatrixArray(2*(nbins), irow, icol, coeff);
	
	delete[] icol;
	delete[] irow;
	delete[] coeff;

// (7) Calculate the covariance matrix - will be symmetric
	TMatrixF COV_USER(G, TMatrixF::kMult, COV_EVAL);
	COV_USER *= G.T();
	//COV_USER.TMatrixF::Mult(COV_USER, G.T());
	
	//delete COV_USER;
	
	//if (return_TMatrix) return ;
	return;

}

This would indicate that there might be some random behavior. Can you send us the result of running valgrind on your failing case?

I can’t get it to work…

$ valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp root.exe -b -l 
ROOTSYS: Undefined variable.

Note that I am running on lxplus. So $(ROOTSYS) is not defined there…

I’ve managed to do it. The output is below!

$ valgrind --suppressions=/afs/cern.ch/sw/lcg/app/releases/ROOT/5.34.36/x86_64-slc6-gcc48-opt/root/etc/valgrind-root.supp root.exe -b -l
==26700== Memcheck, a memory error detector
==26700== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==26700== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==26700== Command: root.exe -b -l
==26700== 
root [0] .L matrix.C+
Info in <TUnixSystem::ACLiC>: creating shared library /eos/user/a/astamato/Forums/RootForum/./matrix_C.so
In file included from /eos/user/a/astamato/Forums/RootForum/matrix_C_ACLiC_dict.h:34,
                 from /eos/user/a/astamato/Forums/RootForum/matrix_C_ACLiC_dict.cxx:17:
/eos/user/a/astamato/Forums/RootForum/./matrix.C:20: warning: unused parameter ‘return_TMatrix’
root [1] covariance_linear_interpolation("ENDF_B-VII_1.dat", 0)
==26700== Invalid write of size 4
==26700==    at 0xC92F372: covariance_linear_interpolation(TString, bool) (matrix.C:29)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63395DD: G__exec_tempfile_fp (in /usr/lib64/root/libCint.so.5.34)
==26700==  Address 0xda18090 is 0 bytes after a block of size 48,000 alloc'd
==26700==    at 0x4C29192: operator new[](unsigned long) (vg_replace_malloc.c:363)
==26700==    by 0xC92F334: covariance_linear_interpolation(TString, bool) (matrix.C:26)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700== 
==26700== Invalid read of size 4
==26700==    at 0xC92DE30: linear_interpolation(int, int, float*, float*, float*, float*, int*) (covariance_lib.cc:14)
==26700==    by 0xC92F42D: covariance_linear_interpolation(TString, bool) (matrix.C:39)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700==  Address 0xda18090 is 0 bytes after a block of size 48,000 alloc'd
==26700==    at 0x4C29192: operator new[](unsigned long) (vg_replace_malloc.c:363)
==26700==    by 0xC92F334: covariance_linear_interpolation(TString, bool) (matrix.C:26)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700== 
==26700== Invalid write of size 4
==26700==    at 0xC92DEA3: linear_interpolation(int, int, float*, float*, float*, float*, int*) (covariance_lib.cc:22)
==26700==    by 0xC92F42D: covariance_linear_interpolation(TString, bool) (matrix.C:39)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700==  Address 0xdf29f10 is 0 bytes after a block of size 48,000 alloc'd
==26700==    at 0x4C29192: operator new[](unsigned long) (vg_replace_malloc.c:363)
==26700==    by 0xC92F3E9: covariance_linear_interpolation(TString, bool) (matrix.C:37)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700== 
==26700== Invalid write of size 4
==26700==    at 0xC92DEE3: linear_interpolation(int, int, float*, float*, float*, float*, int*) (covariance_lib.cc:29)
==26700==    by 0xC92F42D: covariance_linear_interpolation(TString, bool) (matrix.C:39)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700==  Address 0xdf06a40 is 0 bytes after a block of size 48,000 alloc'd
==26700==    at 0x4C29192: operator new[](unsigned long) (vg_replace_malloc.c:363)
==26700==    by 0xC92F3BD: covariance_linear_interpolation(TString, bool) (matrix.C:34)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700== 
==26700== Warning: set address range perms: large range [0x3aeef040, 0x8042a8f8) (undefined)
==26700== Warning: set address range perms: large range [0x8042b040, 0x10ae8a8e4) (undefined)
==26700== Source and destination overlap in memcpy(0x8042b040, 0x3aeef040, -1968834396)
==26700==    at 0x4C2ABCE: memcpy (mc_replace_strmem.c:882)
==26700==    by 0xAFFFDCF: TMatrixTBase<float>::SetMatrixArray(float const*, char const*) (in /usr/lib64/root/libMatrix.so.5.34)
==26700==    by 0xB02B3B8: TMatrixTSym<float>::SetMatrixArray(float const*, char const*) (in /usr/lib64/root/libMatrix.so.5.34)
==26700==    by 0xB02C626: TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) (in /usr/lib64/root/libMatrix.so.5.34)
==26700==    by 0xC92F4E0: covariance_linear_interpolation(TString, bool) (matrix.C:51)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700== 
==26700== Invalid read of size 8
==26700==    at 0x4C2AD4C: memcpy (mc_replace_strmem.c:882)
==26700==    by 0xAFFFDCF: TMatrixTBase<float>::SetMatrixArray(float const*, char const*) (in /usr/lib64/root/libMatrix.so.5.34)
==26700==    by 0xB02B3B8: TMatrixTSym<float>::SetMatrixArray(float const*, char const*) (in /usr/lib64/root/libMatrix.so.5.34)
==26700==    by 0xB02C626: TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) (in /usr/lib64/root/libMatrix.so.5.34)
==26700==    by 0xC92F4E0: covariance_linear_interpolation(TString, bool) (matrix.C:51)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==  Address 0x8042b038 is 8 bytes before a block of size 2,326,132,900 alloc'd
==26700==    at 0x4C29192: operator new[](unsigned long) (vg_replace_malloc.c:363)
==26700==    by 0xB0297E0: TMatrixTSym<float>::Allocate(int, int, int, int, int, int) (in /usr/lib64/root/libMatrix.so.5.34)
==26700==    by 0xB02C618: TMatrixTSym<float>::TMatrixTSym(int, float const*, char const*) (in /usr/lib64/root/libMatrix.so.5.34)
==26700==    by 0xC92F4E0: covariance_linear_interpolation(TString, bool) (matrix.C:51)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700== 
==26700== Warning: set address range perms: large range [0x3aeef028, 0x8042a910) (noaccess)
==26700== Invalid read of size 4
==26700==    at 0xC92F56F: covariance_linear_interpolation(TString, bool) (matrix.C:67)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63395DD: G__exec_tempfile_fp (in /usr/lib64/root/libCint.so.5.34)
==26700==  Address 0xdf29f10 is 0 bytes after a block of size 48,000 alloc'd
==26700==    at 0x4C29192: operator new[](unsigned long) (vg_replace_malloc.c:363)
==26700==    by 0xC92F3E9: covariance_linear_interpolation(TString, bool) (matrix.C:37)
==26700==    by 0xC92F88F: G__matrix_C_ACLiC_dict__0_2358(G__value*, char const*, G__param*, int) (matrix_C_ACLiC_dict.cxx:82)
==26700==    by 0x62F7BA8: Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x639FED0: G__execute_call (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63A0D21: G__call_cppfunc (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x637FA04: G__interpret_func (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x636E917: G__getfunction (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x634D12D: G__getitem (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x6351CB7: G__getexpr (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63CCBE6: G__exec_statement (in /usr/lib64/root/libCint.so.5.34)
==26700==    by 0x63392D0: ??? (in /usr/lib64/root/libCint.so.5.34)
==26700== 
==26700== Warning: set address range perms: large range [0x8042b028, 0x10ae8a8fc) (noaccess)
root [2] .q
==26700== 
==26700== HEAP SUMMARY:
==26700==     in use at exit: 8,719,633 bytes in 53,508 blocks
==26700==   total heap usage: 273,979 allocs, 220,471 frees, 3,524,706,379 bytes allocated
==26700== 
==26700== LEAK SUMMARY:
==26700==    definitely lost: 0 bytes in 0 blocks
==26700==    indirectly lost: 0 bytes in 0 blocks
==26700==      possibly lost: 34 bytes in 1 blocks
==26700==    still reachable: 7,572,040 bytes in 44,288 blocks
==26700==         suppressed: 1,147,559 bytes in 9,219 blocks
==26700== Rerun with --leak-check=full to see details of leaked memory
==26700== 
==26700== For counts of detected and suppressed errors, rerun with: -v
==26700== ERROR SUMMARY: 48282 errors from 7 contexts (suppressed: 585 from 61)

Line 29 reads:

and it runs from 0 to nbins included.
That’s a one element past the En_USER end.
Your for-loop should be written as:

	for(int i=0; i < nbins; i++) {
		En_USER[i] = (float) pow(10., step * (float) i + E_MIN);
	}

or create your En_USER with a size of nbins+1.

Oh I see!
So it’s not related to memory issues!
Thank you very much!

I also have another issue…

When running the code for large matrices (i.e. 25000 x 25000) I can’t get it to finish.
I was leaving it running for about 5 hours and it was still running.

Any idea or advice to make it faster?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.