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

final changes

parent 4dd1c58c
......@@ -81,6 +81,7 @@ static UNUSED int dummy_mt_pth;
#define __AttachHive SAC_MT_TR_AttachHive
#define __DetachHive SAC_MT_TR_DetachHive
#define __ReleaseQueen SAC_MT_TR_ReleaseQueen
#define __LaunchWorker SAC_MT_TR_LaunchWorker
#else
/* no trace */
#define __ReleaseHive SAC_MT_ReleaseHive
......@@ -89,6 +90,7 @@ static UNUSED int dummy_mt_pth;
#define __AttachHive SAC_MT_AttachHive
#define __DetachHive SAC_MT_DetachHive
#define __ReleaseQueen SAC_MT_ReleaseQueen
#define __LaunchWorker SAC_MT_LaunchWorker
#endif
/*
......@@ -202,22 +204,32 @@ tls_destroy_self_bee_key (void *data)
static void
ThreadServeLoop (struct sac_bee_pth_t *SAC_MT_self)
{
printf ("%s \n", "SCC CODE ThreadServceLoop");
printf ("%s %p \n", "SCC CODE ThreadServceLoop", SAC_MT_self);
fflush (NULL);
printf ("Worker thread H:%p, L:%d ready. \n", SAC_MT_self->c.hive,
SAC_MT_self->c.local_id);
fflush (NULL);
for (;;) {
SAC_TR_PRINT (("Worker thread H:%p, L:%d ready.", SAC_MT_self->c.hive,
SAC_MT_self->c.local_id));
/*SAC_TR_PRINT(("Worker thread H:%p, L:%d ready.",
SAC_MT_self->c.hive, SAC_MT_self->c.local_id)); */
/* wait on start lock: the queen will release it when all is ready
* 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);
fflush (NULL);
SAC_MT_PTH_wait_on_barrier (&SAC_MT_self->start_barr_locfl,
&CAST_HIVE_COMMON_TO_PTH (SAC_MT_self->c.hive)
->start_barr_sharedfl);
printf ("%s num_bees: %u \n", "check hive", SAC_MT_self->c.hive->num_bees);
fflush (NULL);
/* check there is a hive */
assert (SAC_MT_self->c.hive);
// printf("%s %s %d \n", "run function",
// SAC_MT_self->c.hive->spmd_fun,SAC_MT_self->c.hive->spmd_fun); fflush(NULL);
/* run SPMD; the barrier is in the function */
printf ("%s \n", "run function");
fflush (NULL);
CAST_HIVE_COMMON_TO_PTH (SAC_MT_self->c.hive)->spmd_fun (SAC_MT_self);
}
}
......@@ -240,44 +252,53 @@ ThreadServeLoop (struct sac_bee_pth_t *SAC_MT_self)
static void *
ThreadControl (void *arg)
{
printf ("%s \n", "test 0");
fflush (NULL);
/* 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;
assert (SAC_MT_self && SAC_MT_self->c.hive);
assert (SAC_MT_self->c.local_id >= 2);
assert (SAC_MT_self->c.local_id >= 1);
printf ("%s \n", "test 1");
fflush (NULL);
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.local_id;
printf ("%s \n", "test 2");
fflush (NULL);
/* correct worker class */
while ((SAC_MT_self->c.local_id + SAC_MT_self->c.b_class)
>= SAC_MT_self->c.hive->num_bees) {
SAC_MT_self->c.b_class >>= 1;
}
SAC_TR_PRINT (("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));
printf ("%s \n", "test 3");
fflush (NULL);
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));
printf ("%s \n", "test 4");
fflush (NULL);
struct sac_hive_pth_t *const hive = CAST_HIVE_COMMON_TO_PTH (SAC_MT_self->c.hive);
printf ("%s \n", "test 5");
fflush (NULL);
/* create other */
for (unsigned i = SAC_MT_self->c.b_class; i; i >>= 1) {
assert ((SAC_MT_self->c.local_id + i) < hive->c.num_bees);
struct sac_bee_pth_t *bee
= CAST_BEE_COMMON_TO_PTH (hive->c.bees[SAC_MT_self->c.local_id + i]);
bee->c.b_class = (i >> 1);
SAC_TR_PRINT (("Creating thread L:%u with maximum class %u.", bee->c.local_id,
bee->c.b_class));
if (0 != pthread_create (&bee->pth, &SAC_MT_thread_attribs, ThreadControl, bee)) {
SAC_RuntimeError ("Multi Thread Error: worker thread L:%u failed to create"
"worker thread L:%u",
SAC_MT_self->c.local_id, bee->c.local_id);
}
}
/*for (unsigned i = SAC_MT_self->c.b_class; i; i >>= 1) {
assert((SAC_MT_self->c.local_id + i) < hive->c.num_bees);
struct sac_bee_pth_t *bee =
CAST_BEE_COMMON_TO_PTH(hive->c.bees[SAC_MT_self->c.local_id + i]); bee->c.b_class = (i
>> 1);
SAC_TR_PRINT(("Creating thread L:%u with maximum class %u.",
bee->c.local_id, bee->c.b_class));
if (0 != pthread_create(
&bee->pth,
&SAC_MT_thread_attribs,
ThreadControl,
bee)) {
SAC_RuntimeError("Multi Thread Error: worker thread L:%u failed to create"
"worker thread L:%u", SAC_MT_self->c.local_id, bee->c.local_id);
}
}*/
#if ENABLE_HWLOC
if (SAC_HWLOC_topology) {
......@@ -290,7 +311,8 @@ ThreadControl (void *arg)
}
}
#endif
printf ("%s \n", "test 7");
fflush (NULL);
ThreadServeLoop (SAC_MT_self);
return SAC_MT_self;
}
......@@ -323,27 +345,29 @@ ThreadControlInitialWorker (void *arg)
SAC_MT_self->c.thread_id = (SAC_HM_DiscoversThreads ()) ? SAC_HM_CurrentThreadId ()
: SAC_MT_self->c.local_id;
SAC_TR_PRINT (("This is worker thread L:1, H:%p, T:%d with class 0.",
SAC_TR_PRINT (("This123 is worker thread L:1, H:%p, T:%d with class 0.",
SAC_MT_self->c.hive, SAC_MT_self->c.thread_id));
/* start creating other bees */
struct sac_hive_pth_t *const hive = CAST_HIVE_COMMON_TO_PTH (SAC_MT_self->c.hive);
const unsigned queen_class = hive->c.queen_class;
printf ("Initial123 WORKER! num_bees %d", hive->c.num_bees);
/*for (unsigned i = queen_class; i > 1; i >>= 1) {
assert(i < hive->c.num_bees);
struct sac_bee_pth_t *bee = CAST_BEE_COMMON_TO_PTH(hive->c.bees[i]);
bee->c.b_class = (i >> 1);
for (unsigned i = queen_class; i > 1; i >>= 1) {
assert (i < hive->c.num_bees);
struct sac_bee_pth_t *bee = CAST_BEE_COMMON_TO_PTH (hive->c.bees[i]);
bee->c.b_class = (i >> 1);
SAC_TR_PRINT (("Creating thread #%u with maximum class %u.", i, bee->c.b_class));
SAC_TR_PRINT(("Creating thread #%u with maximum class %u.", i, bee->c.b_class));
if (0 != pthread_create (&bee->pth, &SAC_MT_thread_attribs, ThreadControl, bee)) {
if (0 != pthread_create(&bee->pth,
&SAC_MT_thread_attribs,
ThreadControl,
bee)) {
SAC_RuntimeError ("Multi Thread Error: worker thread #1 failed to create"
"worker thread #%u",
i);
}
}
SAC_RuntimeError("Multi Thread Error: worker thread #1 failed to create"
"worker thread #%u", i);
}
}*/
#if ENABLE_HWLOC
if (SAC_HWLOC_topology) {
......@@ -637,11 +661,35 @@ SAC_MT_AllocHive (unsigned int num_bees, int num_schedulers, const int *places,
if (hive->c.num_bees > 1) {
SAC_TR_PRINT (("Creating worker thread #1 of class 0"));
if (0
!= pthread_create (&CAST_BEE_COMMON_TO_PTH (hive->c.bees[1])->pth,
&SAC_MT_thread_attribs, ThreadControlInitialWorker,
hive->c.bees[1])) {
SAC_RuntimeError ("Unable to create (initial) worker thread #1");
/* if (0 != pthread_create( &CAST_BEE_COMMON_TO_PTH(hive->c.bees[1])->pth,
&SAC_MT_thread_attribs,
ThreadControlInitialWorker,
hive->c.bees[1])) {
SAC_RuntimeError( "Unable to create (initial) worker thread #1");
}*/
int i;
printf ("NUM BEES: %u \n", hive->c.num_bees);
printf ("HIVE: %p, again %p \n", hive, hive->c.bees[i - 1]->hive);
for (i = 2; i <= hive->c.num_bees; i++) {
int offset = scc_subtract_pointer (hive->c.bees[i - 1]);
printf (
"hive int: %d hive addr: %p, hive addr2: %p offset: %d num_bees: %u \n",
hive->c.bees[i - 1], hive->c.bees[i - 1], &hive->c.bees[i - 1],
hive->c.num_bees);
char command[256];
strcpy (command, "ssh 192.168.0.");
char end[2];
sprintf (end, "%d", i);
strcat (command, end);
strcat (command, " -f \"/shared/jacob/launch_workers -worker ");
char offset_char[128];
sprintf (offset_char, "%d", offset);
strcat (command, offset_char);
strcat (command, " >> /shared/jacob/out.log\"");
printf ("Launch2 command: %s \n", command);
system (command);
printf ("Launch DONE: %s \n", command);
}
}
......@@ -839,7 +887,25 @@ SAC_MT_Internal_CurrentThreadId (void)
}
#endif
#if TRACE
void *
SAC_MT_TR_LaunchWorker (void *arg)
#else
void *
SAC_MT_LaunchWorker (void *arg)
#endif
{
printf ("%s pointer: %p \n", "HELLO??", arg);
fflush (NULL);
struct sac_bee_pth_t *self = (struct sac_bee_pth_t *)arg;
printf ("localid: %d \n", self->c.local_id);
// int num_bees = ((struct sac_hive_common_t *)((struct sac_bee_pth_t *)
//arg)->c.hive)->num_bees; printf("%s beeid %d pointer: %p num_bees: %u \n",
// "SAC_MT_LaunchWorker", ((struct sac_bee_pth_t *) arg)->c.local_id,arg,num_bees);
// ThreadServeLoop(arg);
ThreadControl (arg);
return NULL;
}
#else /* SAC_MT_LIB_scc */
#if !TRACE
......
......@@ -198,4 +198,24 @@ scc_getMoreMemory (size_t exp)
return newMemory;
}
// check if process is worker and return the value
int
scc_is_worker (int argc, char *argv[])
{
int result = -1;
int i;
if (argv) {
for (i = 1; i < argc - 1; i++) {
if ((argv[i][0] == '-') && (argv[i][1] == 'w') && (argv[i][2] == 'o')
&& (argv[i][3] == 'r') && (argv[i][4] == 'k') && (argv[i][5] == 'e')
&& (argv[i][6] == 'r') && (argv[i][7] == '\0')) {
result = atoi (argv[i + 1]);
printf ("SCC_IS_WORKER val: \"%s\" result: %d \n", argv[i + 1], result);
break;
}
}
}
printf ("SCC_IS_WORKER2 val: result: %d \n", result);
return result;
}
#endif // if defined(SAC_MT_LIB_scc)
......@@ -691,11 +691,51 @@ GSCprintMainC99 (void)
print_thread_id = (run_mt_pthread || run_mt_lpel) && global.optimize.dophm;
if (run_mt_scc) {
INDENT;
fprintf (global.outfile, "int worker(int offset)\n\n");
INDENT;
fprintf (global.outfile, "{\n");
INDENT;
global.indent++;
fprintf (global.outfile, "printf(\"From worker, offset is %d\", offset);\n");
INDENT;
fprintf (global.outfile, "scc_setupMemory(1);\n");
// set SAC_MT_SELF and call thread serve loop!
// SAC_MT_singleton_queen
// fprintf( global.outfile, "SAC_MT_singleton_queen =
// scc_plus_pointer(offset);\n"); ThreadControl
INDENT;
fprintf (global.outfile, "SAC_MT_TR_LaunchWorker(scc_plus_pointer(offset));\n");
global.indent--;
INDENT;
fprintf (global.outfile, "}\n");
}
INDENT;
fprintf (global.outfile, "int main( int __argc, char *__argv[])\n");
INDENT;
fprintf (global.outfile, "{\n");
global.indent++;
// if scc we need to check if this is a worker
if (run_mt_scc) {
INDENT;
fprintf (global.outfile, "int offset = scc_is_worker(__argc, __argv);\n");
INDENT;
fprintf (global.outfile, "if (offset != -1 ) {\n");
INDENT;
global.indent++;
fprintf (global.outfile, "\n");
INDENT;
fprintf (global.outfile, "printf(\"TEST: \%d \", scc_is_worker(__argc, "
"__argv));worker(offset);\n");
INDENT;
fprintf (global.outfile, "return(offset);\n");
INDENT;
fprintf (global.outfile, "}\n");
global.indent--;
}
fprintf (global.outfile, "printf(\"RUNNING NON WORKER: \%d \", 1);\n");
INDENT;
if (print_thread_id) {
INDENT;
fprintf (global.outfile, "SAC_MT_DECL_MYTHREAD()\n");
......@@ -746,16 +786,6 @@ GSCprintMainC99 (void)
global.indent--;
INDENT;
fprintf (global.outfile, "}\n");
if (run_mt_scc) {
INDENT;
fprintf (global.outfile, "int worker() ;\n\n");
INDENT;
fprintf (global.outfile, "{\n");
INDENT;
fprintf (global.outfile, "}\n");
}
DBUG_RETURN ();
}
......
......@@ -32,7 +32,7 @@ SETTINGS_PROD := -DDBUG_OFF \
#
# Targets to initially generate libsac/libsacphm/libsacprelude for
#
BUILD_TARGETS := seq mt_pth mt_scc scc_static
BUILD_TARGETS := seq mt_pthread mt_scc scc_static
################################################################################
#
......
......@@ -10,7 +10,7 @@
#define CORES (NUM_ROWS * NUM_COLS * NUM_CORES)
#define PAGE_SIZE (16 * 1024 * 1024)
#define LINUX_PRIV_PAGES (53)
#define LINUX_PRIV_PAGES (41)
#define PAGES_PER_CORE (41)
#define MAX_PAGES (10)
#define IRQ_BIT (0x01 << GLCFG_XINTR_BIT)
......
......@@ -177,7 +177,8 @@ CAST_HIVE_COMMON_TO_PTH (struct sac_hive_common_t *cp)
* standalone program execution. */
#define SAC_MT_DEFINE_ST_SELF() \
struct sac_bee_pth_t *const SAC_MT_self \
= (struct sac_bee_pth_t *)SAC_MT_singleton_queen;
= (struct sac_bee_pth_t *)SAC_MT_singleton_queen; \
printf ("num bees: %p \n", SAC_MT_singleton_queen);
/*****************************************************************************/
......@@ -305,7 +306,7 @@ SAC_C_EXTERN void SAC_MT_TR_SetupAsLibraryInitial (void);
SAC_C_EXTERN void SAC_MT_SetupAsLibraryInitial (void);
SAC_C_EXTERN unsigned int SAC_Get_CurrentBee_GlobalID (void);
SAC_C_EXTERN void *SAC_MT_LaunchWorker (void *arg);
#endif /* SAC_DO_MULTITHREAD && SAC_DO_MULTITHREAD && SAC_DO_MT_PTHREAD */
#endif /* SAC_SIMD_COMPILATION */
......
......@@ -9,6 +9,6 @@ int scc_subtract_pointer (void *pointer2);
void *scc_plus_pointer (int offset);
void *scc_getMoreMemory (size_t exp);
void *scc_setupMemory (int num_nodes_active);
int scc_is_worker (int argc, char *argv[]);
// SAC_MIT_LIB_scc:
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment