Commit 8f3d76a0 authored by Jacob Emil Baungard Hansen's avatar Jacob Emil Baungard Hansen
Browse files

Changed all of the pointers in the beehive to use SCC specific pointer offsets

parent cdb71760
...@@ -88,6 +88,8 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers, ...@@ -88,6 +88,8 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers,
unsigned sizeof_hive, unsigned sizeof_bee) unsigned sizeof_hive, unsigned sizeof_bee)
{ {
/* allocate the Hive struct */ /* allocate the Hive struct */
printf ("%s", "AllocHiveCommons -2 \n");
fflush (NULL);
struct sac_hive_common_t *hive struct sac_hive_common_t *hive
= (struct sac_hive_common_t *)SAC_CALLOC (1, sizeof_hive); = (struct sac_hive_common_t *)SAC_CALLOC (1, sizeof_hive);
if (!hive) { if (!hive) {
...@@ -100,8 +102,10 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers, ...@@ -100,8 +102,10 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers,
if (!hive->bees) { if (!hive->bees) {
SAC_RuntimeError ("Could not allocate memory for an array of ptrs to bees."); SAC_RuntimeError ("Could not allocate memory for an array of ptrs to bees.");
} }
printf ("%s", "AllocHiveCommons -1 \n");
fflush (NULL);
// SAC_TR_PRINT( ("Initializing Tasklocks.")); SAC_TR_PRINT (("Initializing Tasklocks."));
if (num_schedulers > 0) { if (num_schedulers > 0) {
/* allocate scheduler's data structures in the hive */ /* allocate scheduler's data structures in the hive */
hive->SAC_MT_Tasklock = (pthread_mutex_t *)SAC_MALLOC ( hive->SAC_MT_Tasklock = (pthread_mutex_t *)SAC_MALLOC (
...@@ -116,6 +120,9 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers, ...@@ -116,6 +120,9 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers,
= (pthread_mutex_t *)SAC_MALLOC (num_schedulers * sizeof (pthread_mutex_t)); = (pthread_mutex_t *)SAC_MALLOC (num_schedulers * sizeof (pthread_mutex_t));
hive->SAC_MT_Taskcount = (int *)SAC_CALLOC (num_schedulers, sizeof (int)); hive->SAC_MT_Taskcount = (int *)SAC_CALLOC (num_schedulers, sizeof (int));
printf ("%s", "AllocHiveCommons -0 \n");
fflush (NULL);
/* check success */ /* check success */
if (!hive->SAC_MT_Tasklock || !hive->SAC_MT_Task || !hive->SAC_MT_LAST_Task if (!hive->SAC_MT_Tasklock || !hive->SAC_MT_Task || !hive->SAC_MT_LAST_Task
|| !hive->SAC_MT_rest_iterations || !hive->SAC_MT_act_tasksize || !hive->SAC_MT_rest_iterations || !hive->SAC_MT_act_tasksize
...@@ -124,6 +131,42 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers, ...@@ -124,6 +131,42 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers,
SAC_RuntimeError ( SAC_RuntimeError (
"Could not allocate memory for scheduling data in the hive!"); "Could not allocate memory for scheduling data in the hive!");
} }
printf ("%s", "AllocHiveCommons 1 \n");
fflush (NULL);
printf ("tasklock pointer (before) %p \n ", hive->SAC_MT_Tasklock);
// change the SAC_MT elements to offsets in the SCC case.
#if defined(SAC_MT_LIB_scc)
printf ("%s \n", "AllocHiveCommons 1.5");
fflush (NULL);
hive->SAC_MT_Tasklock = scc_subtract_pointer (hive->SAC_MT_Tasklock);
printf ("%s %d\n", "offset: ", hive->SAC_MT_Tasklock);
fflush (NULL);
hive->SAC_MT_Task = scc_subtract_pointer (hive->SAC_MT_Task);
hive->SAC_MT_LAST_Task = scc_subtract_pointer (hive->SAC_MT_LAST_Task);
hive->SAC_MT_rest_iterations
= scc_subtract_pointer (hive->SAC_MT_rest_iterations);
hive->SAC_MT_act_tasksize = scc_subtract_pointer (hive->SAC_MT_act_tasksize);
hive->SAC_MT_last_taskend = scc_subtract_pointer (hive->SAC_MT_last_taskend);
hive->SAC_MT_TS_Tasklock = scc_subtract_pointer (hive->SAC_MT_TS_Tasklock);
hive->SAC_MT_Taskcount = scc_subtract_pointer (hive->SAC_MT_Taskcount);
#endif
printf ("%s", "AllocHiveCommons 2 \n");
fflush (NULL);
pthread_mutex_t *tasklock_two
= (pthread_mutex_t *)scc_plus_pointer ((int)hive->SAC_MT_Tasklock);
printf ("tasklock pointer (after plus) %p idx 0 %p inline %p \n ", tasklock_two,
&tasklock_two[0],
&((pthread_mutex_t *)scc_plus_pointer (hive->SAC_MT_Tasklock))[0]);
fflush (NULL);
pthread_mutex_init (&tasklock_two[0], NULL);
// printf("tasklock pointer macro %p \n", &(SAC_MT_TASKLOCK_INIT( hive, 0, 0,
// 1))); fflush(NULL);
// pthread_mutex_init( &(SAC_MT_TASKLOCK_INIT( hive, 0, 0, 1)), NULL);
/* initialize the mutexes in the scheduler's data */ /* initialize the mutexes in the scheduler's data */
for (unsigned n = 0; n < num_schedulers; ++n) { for (unsigned n = 0; n < num_schedulers; ++n) {
...@@ -135,9 +178,10 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers, ...@@ -135,9 +178,10 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers,
// pthread_mutex_init( &(hive->SAC_MT_Tasklock[n + num_schedulers * i]), // pthread_mutex_init( &(hive->SAC_MT_Tasklock[n + num_schedulers * i]),
// NULL); // NULL);
} }
pthread_mutex_t *tasklock
= (pthread_mutex_t *)scc_plus_pointer ((int)hive->SAC_MT_TS_Tasklock);
/* init pthread_mutex_t SAC_MT_TS_Tasklock[SAC_SET_NUM_SCHEDULERS]; */ /* init pthread_mutex_t SAC_MT_TS_Tasklock[SAC_SET_NUM_SCHEDULERS]; */
pthread_mutex_init (&(hive->SAC_MT_TS_Tasklock[n]), NULL); pthread_mutex_init (&(tasklock[n]), NULL);
} }
} }
...@@ -157,6 +201,15 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers, ...@@ -157,6 +201,15 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers,
* bees, not the queen bee itself */ * bees, not the queen bee itself */
struct sac_bee_common_t *b struct sac_bee_common_t *b
= (struct sac_bee_common_t *)(other_bees + sizeof_bee * (i - 1)); = (struct sac_bee_common_t *)(other_bees + sizeof_bee * (i - 1));
#if defined(SAC_MT_LIB_scc)
/* put a bee into hive */
hive->bees[i] = scc_subtract_pointer (b);
/* set bee's data */
b->local_id = i;
b->thread_id
= SAC_HM_THREADID_INVALID; /* must be assigned within the thread! */
b->hive = scc_subtract_pointer (hive);
#else
/* put a bee into hive */ /* put a bee into hive */
hive->bees[i] = b; hive->bees[i] = b;
/* set bee's data */ /* set bee's data */
...@@ -164,6 +217,7 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers, ...@@ -164,6 +217,7 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers,
b->thread_id b->thread_id
= SAC_HM_THREADID_INVALID; /* must be assigned within the thread! */ = SAC_HM_THREADID_INVALID; /* must be assigned within the thread! */
b->hive = hive; b->hive = hive;
#endif
} }
} }
...@@ -174,8 +228,11 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers, ...@@ -174,8 +228,11 @@ SAC_MT_Helper_AllocHiveCommons (unsigned num_bees, unsigned num_schedulers,
hive->queen_class >>= 1; hive->queen_class >>= 1;
/* increment the number of hives in the system */ // change the SAC_MT elements to offsets in the SCC case.
#if defined(SAC_MT_LIB_scc) #if defined(SAC_MT_LIB_scc)
printf ("Bees pointer before offset %p \n ", hive->bees);
hive->bees = scc_subtract_pointer (hive->bees);
SAC_MT_cnt_hives += 1; SAC_MT_cnt_hives += 1;
SAC_MT_cnt_worker_bees += num_bees - 1; SAC_MT_cnt_worker_bees += num_bees - 1;
#else #else
...@@ -200,12 +257,51 @@ SAC_MT_Helper_FreeHiveCommons (struct sac_hive_common_t *hive) ...@@ -200,12 +257,51 @@ SAC_MT_Helper_FreeHiveCommons (struct sac_hive_common_t *hive)
{ {
/* decrement the number of hives in the environment */ /* decrement the number of hives in the environment */
#if defined(SAC_MT_LIB_scc) #if defined(SAC_MT_LIB_scc)
printf ("%s other bee:", "RelaseHive Commons 1 \n");
fflush (NULL);
if (hive->num_bees > 1) {
/* the other_bees ptr below is equal to the identically-named variable in
* SAC_MT_Helper_AllocHiveCommons() */
struct sac_bee_common_t **bees
= (struct sac_bee_common_t **)scc_plus_pointer (hive->bees);
printf ("%s bees: %p \n", "RelaseHive Commons 1 \n", bees);
fflush (NULL);
printf ("bee[1] %p \n", bees[1]);
fflush (NULL);
struct sac_bee_common_t *other_bees
= (struct sac_bee_common_t *)scc_plus_pointer (bees[1]);
printf ("%s \n", "free other bee", bees[1]);
fflush (NULL);
SAC_FREE (other_bees);
}
printf ("%s", "RelaseHive Commons 2 \n");
fflush (NULL);
/* free the array of pointers */
SAC_FREE (scc_plus_pointer (hive->bees));
hive->bees = NULL;
printf ("%s", "RelaseHive Commons 3 \n");
fflush (NULL);
/* free the scheduler's data; typecast due to volatile */
SAC_FREE ((void *)scc_plus_pointer (hive->SAC_MT_Tasklock));
SAC_FREE ((void *)scc_plus_pointer (hive->SAC_MT_Task));
SAC_FREE ((void *)scc_plus_pointer (hive->SAC_MT_LAST_Task));
SAC_FREE ((void *)scc_plus_pointer (hive->SAC_MT_rest_iterations));
SAC_FREE ((void *)scc_plus_pointer (hive->SAC_MT_act_tasksize));
SAC_FREE ((void *)scc_plus_pointer (hive->SAC_MT_last_taskend));
SAC_FREE ((void *)scc_plus_pointer (hive->SAC_MT_TS_Tasklock));
SAC_FREE ((void *)scc_plus_pointer (hive->SAC_MT_Taskcount));
printf ("%s", "RelaseHive Commons 4 \n");
fflush (NULL);
SAC_MT_cnt_hives -= 1; SAC_MT_cnt_hives -= 1;
SAC_MT_cnt_worker_bees -= hive->num_bees - 1; SAC_MT_cnt_worker_bees -= hive->num_bees - 1;
printf ("%s", "RelaseHive Commons 5 \n");
fflush (NULL);
#else #else
__sync_sub_and_fetch (&SAC_MT_cnt_hives, 1);
__sync_sub_and_fetch (&SAC_MT_cnt_worker_bees, hive->num_bees - 1);
#endif
if (hive->num_bees > 1) { if (hive->num_bees > 1) {
/* the other_bees ptr below is equal to the identically-named variable in /* the other_bees ptr below is equal to the identically-named variable in
...@@ -228,8 +324,14 @@ SAC_MT_Helper_FreeHiveCommons (struct sac_hive_common_t *hive) ...@@ -228,8 +324,14 @@ SAC_MT_Helper_FreeHiveCommons (struct sac_hive_common_t *hive)
SAC_FREE ((void *)hive->SAC_MT_TS_Tasklock); SAC_FREE ((void *)hive->SAC_MT_TS_Tasklock);
SAC_FREE ((void *)hive->SAC_MT_Taskcount); SAC_FREE ((void *)hive->SAC_MT_Taskcount);
__sync_sub_and_fetch (&SAC_MT_cnt_hives, 1);
__sync_sub_and_fetch (&SAC_MT_cnt_worker_bees, hive->num_bees - 1);
#endif
/* free the hive itself */ /* free the hive itself */
SAC_FREE (hive); SAC_FREE (hive);
printf ("%s \n", "End of FreeHiveCommons");
fflush (NULL);
} }
/**************************************************************************** /****************************************************************************
...@@ -250,12 +352,28 @@ void ...@@ -250,12 +352,28 @@ void
SAC_MT_Generic_AttachHive (struct sac_hive_common_t *hive, struct sac_bee_common_t *queen) SAC_MT_Generic_AttachHive (struct sac_hive_common_t *hive, struct sac_bee_common_t *queen)
#endif #endif
{ {
printf ("genericattachhive hive: %p, queen %p \n", hive, queen);
fflush (NULL);
/* check: the hive must not be already attached */ /* check: the hive must not be already attached */
if (hive->bees[0]) { struct sac_bee_common_t **bees;
#if defined(SAC_MT_LIB_scc)
printf ("%s %p \n", "generic attach SCC SPECIFIC! ", hive->bees);
fflush (NULL);
bees = (struct sac_bee_common_t **)scc_plus_pointer (hive->bees);
printf ("%s %p \n", "generic attach SCC SPECIFIC! ", bees);
fflush (NULL);
#else
bees = hive->bees;
#endif
printf ("%s %p bees \n", "generic attach hive -1 bees: ", bees);
fflush (NULL);
if (bees[0]) {
SAC_RuntimeError ("AttachHive: Cannot attach a hive which is already attached!" SAC_RuntimeError ("AttachHive: Cannot attach a hive which is already attached!"
" Call DetachHive() first."); " Call DetachHive() first.");
return; return;
} }
printf ("%s %p \n", "generic attach hive 0 quenn->hive: ", queen->hive);
fflush (NULL);
if (queen->hive) { if (queen->hive) {
/* destroy the current hive */ /* destroy the current hive */
...@@ -264,11 +382,18 @@ SAC_MT_Generic_AttachHive (struct sac_hive_common_t *hive, struct sac_bee_common ...@@ -264,11 +382,18 @@ SAC_MT_Generic_AttachHive (struct sac_hive_common_t *hive, struct sac_bee_common
/* now we're a queen without any hive */ /* now we're a queen without any hive */
assert (!queen->hive); assert (!queen->hive);
printf ("%s \n", "generic attach hive 1");
fflush (NULL);
/* put the queen in the hive */ /* put the queen in the hive */
hive->bees[0] = queen; bees[0] = queen;
printf ("%s \n", "generic attach hive 2");
fflush (NULL);
queen->hive = hive; queen->hive = hive;
printf ("%s \n", "generic attach hive 3");
fflush (NULL);
queen->b_class = hive->queen_class; queen->b_class = hive->queen_class;
printf ("%s \n", "generic attach hive 4");
fflush (NULL);
} }
/************************************************************************** /**************************************************************************
...@@ -298,11 +423,19 @@ SAC_MT_Generic_DetachHive (struct sac_bee_common_t *queen) ...@@ -298,11 +423,19 @@ SAC_MT_Generic_DetachHive (struct sac_bee_common_t *queen)
} }
struct sac_hive_common_t *hive = queen->hive; struct sac_hive_common_t *hive = queen->hive;
printf ("hive: %p \n", hive);
fflush (NULL);
struct sac_bee_common_t **bees;
#if defined(SAC_MT_LIB_scc)
bees = (struct sac_bee_common_t **)scc_plus_pointer (hive->bees);
#else
bees = hive->bees;
#endif
/* check that we're the queen */ /* check that we're the queen */
assert (hive->bees[0] == queen); assert (bees[0] == queen);
/* remove the queen from the hive */ /* remove the queen from the hive */
hive->bees[0] = NULL; bees[0] = NULL;
queen->hive = NULL; queen->hive = NULL;
queen->b_class = 0; queen->b_class = 0;
......
...@@ -204,10 +204,12 @@ tls_destroy_self_bee_key (void *data) ...@@ -204,10 +204,12 @@ tls_destroy_self_bee_key (void *data)
static void static void
ThreadServeLoop (struct sac_bee_pth_t *SAC_MT_self) ThreadServeLoop (struct sac_bee_pth_t *SAC_MT_self)
{ {
struct sac_hive_common_t *common_hive
= (struct sac_hive_common_t *)scc_plus_pointer (SAC_MT_self->c.hive);
printf ("%s %p \n", "SCC CODE ThreadServceLoop", SAC_MT_self); printf ("%s %p \n", "SCC CODE ThreadServceLoop", SAC_MT_self);
fflush (NULL); fflush (NULL);
printf ("Worker thread H:%p, L:%d ready. \n", SAC_MT_self->c.hive, printf ("Worker thread H:%p, L:%d ready. \n", common_hive, SAC_MT_self->c.local_id);
SAC_MT_self->c.local_id);
fflush (NULL); fflush (NULL);
for (;;) { for (;;) {
/*SAC_TR_PRINT(("Worker thread H:%p, L:%d ready.", /*SAC_TR_PRINT(("Worker thread H:%p, L:%d ready.",
...@@ -215,22 +217,26 @@ ThreadServeLoop (struct sac_bee_pth_t *SAC_MT_self) ...@@ -215,22 +217,26 @@ ThreadServeLoop (struct sac_bee_pth_t *SAC_MT_self)
/* wait on start lock: the queen will release it when all is ready /* wait on start lock: the queen will release it when all is ready
* for an SPMD execution */ * for an SPMD execution */
printf ("%s 1: %p 2: %p \n", "wait_on_barrier", &SAC_MT_self->start_barr_locfl,
SAC_MT_self->start_barr_locfl); printf ("%s addr_locl: %p val_locl: %u addr_shared %p val_shared %u \n",
"wait_on_barrier", &SAC_MT_self->start_barr_locfl,
SAC_MT_self->start_barr_locfl,
&CAST_HIVE_COMMON_TO_PTH (common_hive)->start_barr_sharedfl,
CAST_HIVE_COMMON_TO_PTH (common_hive)->start_barr_sharedfl);
fflush (NULL); fflush (NULL);
SAC_MT_PTH_wait_on_barrier (&SAC_MT_self->start_barr_locfl, SAC_MT_PTH_wait_on_barrier (&SAC_MT_self->start_barr_locfl,
&CAST_HIVE_COMMON_TO_PTH (SAC_MT_self->c.hive) &CAST_HIVE_COMMON_TO_PTH (common_hive)
->start_barr_sharedfl); ->start_barr_sharedfl);
printf ("%s num_bees: %u \n", "check hive", SAC_MT_self->c.hive->num_bees); printf ("%s num_bees: %u \n", "check hive", common_hive->num_bees);
fflush (NULL); fflush (NULL);
/* check there is a hive */ /* check there is a hive */
assert (SAC_MT_self->c.hive); assert (common_hive);
// printf("%s %s %d \n", "run function", // printf("%s %s %d \n", "run function",
// SAC_MT_self->c.hive->spmd_fun,SAC_MT_self->c.hive->spmd_fun); fflush(NULL); // SAC_MT_self->c.hive->spmd_fun,SAC_MT_self->c.hive->spmd_fun); fflush(NULL);
/* run SPMD; the barrier is in the function */ /* run SPMD; the barrier is in the function */
printf ("%s \n", "run function"); printf ("%s \n", "run function ");
fflush (NULL); fflush (NULL);
CAST_HIVE_COMMON_TO_PTH (SAC_MT_self->c.hive)->spmd_fun (SAC_MT_self); CAST_HIVE_COMMON_TO_PTH (common_hive)->spmd_fun (SAC_MT_self);
} }
} }
...@@ -256,27 +262,30 @@ ThreadControl (void *arg) ...@@ -256,27 +262,30 @@ ThreadControl (void *arg)
fflush (NULL); fflush (NULL);
/* This is executed in the bee >1 of a new hive */ /* This is executed in the bee >1 of a new hive */
struct sac_bee_pth_t *const SAC_MT_self = (struct sac_bee_pth_t *)arg; struct sac_bee_pth_t *const SAC_MT_self = (struct sac_bee_pth_t *)arg;
assert (SAC_MT_self && SAC_MT_self->c.hive); struct sac_hive_common_t *common_hive
= (struct sac_hive_common_t *)scc_plus_pointer (SAC_MT_self->c.hive);
assert (SAC_MT_self && common_hive);
assert (SAC_MT_self->c.local_id >= 1); assert (SAC_MT_self->c.local_id >= 1);
printf ("%s \n", "test 1"); printf ("%s localid %u %p\n", "test 1", SAC_MT_self->c.local_id,
&SAC_MT_self->c.local_id);
fflush (NULL); fflush (NULL);
pthread_setspecific (SAC_MT_self_bee_key, SAC_MT_self); pthread_setspecific (SAC_MT_self_bee_key, SAC_MT_self);
SAC_MT_self->c.thread_id = (SAC_HM_DiscoversThreads ()) ? SAC_HM_CurrentThreadId () SAC_MT_self->c.thread_id = (SAC_HM_DiscoversThreads ()) ? SAC_HM_CurrentThreadId ()
: SAC_MT_self->c.local_id; : SAC_MT_self->c.local_id;
printf ("%s \n", "test 2"); printf ("%s hive: %p \n", "test 2", common_hive);
fflush (NULL); fflush (NULL);
/* correct worker class */ /* correct worker class */
while ((SAC_MT_self->c.local_id + SAC_MT_self->c.b_class) while ((SAC_MT_self->c.local_id + SAC_MT_self->c.b_class) >= common_hive->num_bees) {
>= SAC_MT_self->c.hive->num_bees) {
SAC_MT_self->c.b_class >>= 1; SAC_MT_self->c.b_class >>= 1;
} }
printf ("%s \n", "test 3"); printf ("%s \n", "test 3");
fflush (NULL); fflush (NULL);
printf ("ThreadControl num_bees: %u", common_hive->num_bees);
printf (("This is worker thread H:%p, L:%u, T:%u with class %u.", SAC_MT_self->c.hive, printf (("This is worker thread H:%p, L:%u, T:%u with class %u.", SAC_MT_self->c.hive,
SAC_MT_self->c.local_id, SAC_MT_self->c.thread_id, SAC_MT_self->c.b_class)); SAC_MT_self->c.local_id, SAC_MT_self->c.thread_id, SAC_MT_self->c.b_class));
printf ("%s \n", "test 4"); printf ("%s \n", "test 4");
fflush (NULL); fflush (NULL);
struct sac_hive_pth_t *const hive = CAST_HIVE_COMMON_TO_PTH (SAC_MT_self->c.hive); struct sac_hive_pth_t *const hive = CAST_HIVE_COMMON_TO_PTH (common_hive);
printf ("%s \n", "test 5"); printf ("%s \n", "test 5");
fflush (NULL); fflush (NULL);
/* create other */ /* create other */
...@@ -528,15 +537,21 @@ EnsureThreadHasBee (void) ...@@ -528,15 +537,21 @@ EnsureThreadHasBee (void)
if (self) { if (self) {
/* ok, there's a bee already */ /* ok, there's a bee already */
printf ("%s %p \n", "Ensure thread has bee - there's already one: ", self);
fflush (NULL);
return self; return self;
} }
/* allocate the bee structure */ /* allocate the bee structure */
self = (struct sac_bee_pth_t *)SAC_CALLOC (1, sizeof (struct sac_bee_pth_t)); self = (struct sac_bee_pth_t *)SAC_CALLOC (1, sizeof (struct sac_bee_pth_t));
if (!self) { if (!self) {
SAC_RuntimeError ("Could not allocate memory for the first bee."); SAC_RuntimeError ("Could not allocate memory for the first bee.");
} }
// printf( "%s queen %p common & %p common %p \n", "Allocating a new bee", self,
// &(self->c), self->c);fflush(NULL);
printf ("%s \n ", "EnsureThreadHasBee");
fflush (NULL);
/* set bee's data */ /* set bee's data */
self->c.local_id = 0; self->c.local_id = 0;
self->c.thread_id self->c.thread_id
...@@ -583,7 +598,10 @@ SAC_MT_ReleaseHive (struct sac_hive_common_t *h) ...@@ -583,7 +598,10 @@ SAC_MT_ReleaseHive (struct sac_hive_common_t *h)
/* no hive, no work */ /* no hive, no work */
return; return;
} }
if (h->bees[0]) {
struct sac_bee_common_t **bees
= (struct sac_bee_common_t **)scc_plus_pointer (h->bees);
if (bees[0]) {
/* there is a queen! */ /* there is a queen! */
SAC_RuntimeError ("SAC_MT_*_ReleaseHive: Cannot release a hive with a queen." SAC_RuntimeError ("SAC_MT_*_ReleaseHive: Cannot release a hive with a queen."
" Call DetachHive() first."); " Call DetachHive() first.");
...@@ -598,15 +616,27 @@ SAC_MT_ReleaseHive (struct sac_hive_common_t *h) ...@@ -598,15 +616,27 @@ SAC_MT_ReleaseHive (struct sac_hive_common_t *h)
SAC_MT_PTH_signal_barrier (NULL, &hive->start_barr_sharedfl); SAC_MT_PTH_signal_barrier (NULL, &hive->start_barr_sharedfl);
/* wait on bees until done */ /* wait on bees until done */
printf ("RelaseHive numbees: %p \n", hive->c.num_bees);
fflush (NULL);
bees = (struct sac_bee_common_t **)scc_plus_pointer (hive->c.bees);
/*for (unsigned i = 1; i < hive->c.num_bees; ++i) {
pthread_join(CAST_BEE_COMMON_TO_PTH(bees[i])->pth, NULL);
}*/
for (unsigned i = 1; i < hive->c.num_bees; ++i) { for (unsigned i = 1; i < hive->c.num_bees; ++i) {
pthread_join (CAST_BEE_COMMON_TO_PTH (hive->c.bees[i])->pth, NULL); // pthread_join(CAST_BEE_COMMON_TO_PTH(bees[i])->pth, NULL);
} }
printf ("RelaseHive numbees 2: %d \n", hive->c.num_bees);
fflush (NULL);
/* now, all slave bees should be dead; release data */ /* now, all slave bees should be dead; release data */
for (unsigned i = 1; i < hive->c.num_bees; ++i) { for (unsigned i = 1; i < hive->c.num_bees; ++i) {
SAC_MT_PTH_destroy_lck (&CAST_BEE_COMMON_TO_PTH (hive->c.bees[i])->stop_lck); SAC_MT_PTH_destroy_lck (&CAST_BEE_COMMON_TO_PTH (bees[i])->stop_lck);
} }
printf ("RelaseHive numbees 3: %p \n", hive->c.num_bees);
fflush (NULL);
/* release the memory */ /* release the memory */
SAC_MT_Helper_FreeHiveCommons (&hive->c); SAC_MT_Helper_FreeHiveCommons (&hive->c);
} }
...@@ -649,18 +679,28 @@ SAC_MT_AllocHive (unsigned int num_bees, int num_schedulers, const int *places, ...@@ -649,18 +679,28 @@ SAC_MT_AllocHive (unsigned int num_bees, int num_schedulers, const int *places,
sizeof (struct sac_hive_pth_t), sizeof (struct sac_hive_pth_t),
sizeof (struct sac_bee_pth_t))); sizeof (struct sac_bee_pth_t)));
struct sac_bee_common_t **bees
= (struct sac_bee_common_t **)scc_plus_pointer ((int)hive->c.bees);
/* setup extended info in bees */ /* setup extended info in bees */
for (unsigned i = 1; i < hive->c.num_bees; ++i) { for (unsigned i = 1; i < hive->c.num_bees; ++i) {
struct sac_bee_pth_t *b = CAST_BEE_COMMON_TO_PTH (hive->c.bees[i]); // struct sac_bee_pth_t *b = CAST_BEE_COMMON_TO_PTH(hive->c.bees[i]);
struct sac_bee_pth_t *b = CAST_BEE_COMMON_TO_PTH (
(struct sac_bee_common_t *)scc_plus_pointer ((int)bees[i]));
/* init locks */ /* init locks */
SAC_MT_INIT_BARRIER (b); SAC_MT_INIT_BARRIER (b);
} }
// pthread_setspecific(SAC_MT_self_bee_key, CAST_BEE_COMMON_TO_PTH( (struct
// sac_bee_common_t *) scc_plus_pointer((int) bees[0])) ) ;
SAC_TR_PRINT (("Thread class of master thread is %d.", (int)hive->c.queen_class)); SAC_TR_PRINT (("Thread class of master thread is %d.", (int)hive->c.queen_class));
SAC_TR_PRINT (("AllocHive - 0 num bees %d", hive->c.num_bees));
if (hive->c.num_bees > 1) { if (hive->c.num_bees > 1) {
SAC_TR_PRINT (("Creating worker thread #1 of class 0")); SAC_TR_PRINT (("Creating worker thread #1 of class 0"));
SAC_TR_PRINT (("AllocHive - 1"));
/* if (0 != pthread_create( &CAST_BEE_COMMON_TO_PTH(hive->c.bees[1])->pth, /* if (0 != pthread_create( &CAST_BEE_COMMON_TO_PTH(hive->c.bees[1])->pth,
&SAC_MT_thread_attribs, &SAC_MT_thread_attribs,
...@@ -669,18 +709,18 @@ SAC_MT_AllocHive (unsigned int num_bees, int num_schedulers, const int *places, ...@@ -669,18 +709,18 @@ SAC_MT_AllocHive (unsigned int num_bees, int num_schedulers, const int *places,
SAC_RuntimeError( "Unable to create (initial) worker thread #1"); SAC_RuntimeError( "Unable to create (initial) worker thread #1");
}*/ }*/
int i; int i;
printf ("NUM BEES: %u \n", hive->c.num_bees); SAC_TR_PRINT (("AllocHive - 2 "));
printf ("HIVE: %p, again %p \n", hive, hive->c.bees[i - 1]->hive); // printf("HIVE: %p, again2 %p num_bees: %u \n", hive, hive->c.bees[1]->hive,
// hive->c.bees[1]->hive->num_bees);
for (i = 2; i <= hive->c.num_bees; i++) { for (i = 2; i <= hive->c.num_bees; i++) {
int offset = scc_subtract_pointer (hive->c.bees[i - 1]); int offset = bees[i - 1];
printf ( // printf("hive int: %d hive addr: %p, hive addr2: %p offset: %d num_bees: %u
"hive int: %d hive addr: %p, hive addr2: %p offset: %d num_bees: %u \n", // \n",hive->c.bees[i-1], hive->c.bees[i-1],
hive->c.bees[i - 1], hive->c.bees[i - 1], &hive->c.bees[i - 1], // &hive->c.bees[i-1],hive->c.num_bees );
hive->c.num_bees);
char command[256];