Parallelisation with pthreads


rostd
11-28-2012, 01:43 AM
Hello everyone,

i am trying to parallelise a function in my simulation, that performs a newton search using frprmn from NR 3 in C. The serial Version of the code works perfect.

Now I start parallel threads with pthread and I get some types of memory errors like
*** glibc detected *** ../dmft: double free or corruption (fasttop):

A memory trace back seems that the error occours, when one of the parallel startetd linmin functions (started from frprmn) tries to free its memory.

This is my parallel function:


void *fit_anderson_thread(void *arg) {
// Allocation
int L=6;
int loc_iter;
int NDIM=2*(L-1)+1;
float FTOL=1.0e-12;
int i,k;
float fret,*p;
double complex * Gtest=malloc(wMax*sizeof(double complex));
// Vector for NR
p=vector(1,NDIM);

th_info * array_loc= (th_info*)arg;

// Copy content
for(i=0; i<(L-1); i++) {
p[i+1]=array_loc->e[i];
p[i+L]=array_loc->V[i];
}
// Newton search
frprmn(p,NDIM,FTOL,&loc_iter,&fret,func,dfunc);

for(i=0; i<(L-1); i++) {
array_loc->e[i]=p[i+1];
array_loc->V[i]=p[i+L];
}

// Free Memory
free_vector(p,1,NDIM);
}

Seems that the parallel runs of the NR routine shares memory, which causes a Memory error. In serial mode no error occurs.

Maybe someone has an idea how to fix it?

Best,
Daniel