Hello All,
I have an interesting sort of error that I'm not sure how to fix.
First, the problem at hand is that I'm getting uninitialized value errors when using two threads with Hoard but when I use the standard malloc, I don't get any such errors. Also, the errors cause me to leak while the standard malloc de-allocates fine.
We have a particle structure :
Code:
struct particle {
long double x;
long double y;
long double z;
};
And we allocate in the main-loop with :
Code:
struct particle *p = malloc(512*sizeof(*p));
for (int x=0; x<8; x++) {
for (int y=0; y<8; y++) {
for (int z=0; z<8; z++) {
p[x*64+y*8+z].x = x;
p[x*64+y*8+z].y = y;
p[x*64+y*8+z].z = z;
}
}
}
But because pthreads are really lame in the way that they only really want a void pointer, I had to declare a threading structure because I need to pass as arguments a pointer to a location in a quadtree and a pointer to a particle from our p pointer, in my case &p[73] is the address.
So, we have :
Code:
struct thread {
struct branch *b;
struct particle *p;
};
void* shear(void *t) {
struct thread *thr = t;
search(thr->b, thr->p);
return NULL;
}
struct thread* buildCell(struct branch *b, struct particle *p) {
struct thread *t = malloc(sizeof(*t));
t->b = b;
t->p = p;
return t;
}
and in my main loop, I have :
Code:
pthread_t shears[2];
struct thread *thr1 = buildCell(root->children[0], &p[73]);
struct thread *thr2 = buildCell(root->children[2], &p[73]);
pthread_create(&shears[0], NULL, shear, thr1);
pthread_create(&shears[1], NULL, shear, thr2);
pthread_join(shears[0], NULL);
pthread_join(shears[1], NULL);
free(thr1);
free(thr2);
root is the root of the quadtree and yes, it has children. It has 4 children at the time p[73] is to be added. And shear is our thread function and thr1 and 2 are the arguments required for search'ing the tree which is a separate function which probes the entire tree given certain conditions, i.e. is the particle within the 'bounding box' or not which is a form of checking for shared edges.
The Hoard errors tell me that my malloc of p yields initialized values but I don't see how considering the standard malloc works fine. Is this is a shortcoming in Hoard?