MAGMA  magma-1.4.0
Matrix Algebra on GPU and Multicore Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
QUARK: QUeuing And Runtime for Kernels

Functions

void * QUARK_Args_List (Quark *quark)
 
void * QUARK_Args_Pop (void *args_list, void **last_arg)
 
QuarkQUARK_Setup (int num_threads)
 
QuarkQUARK_New (int num_threads)
 
void QUARK_Barrier (Quark *quark)
 
void QUARK_Waitall (Quark *quark)
 
void QUARK_Free (Quark *quark)
 
void QUARK_Delete (Quark *quark)
 
TaskQUARK_Task_Init (Quark *quark, void(*function)(Quark *), Quark_Task_Flags *task_flags)
 
void QUARK_Task_Pack_Arg (Quark *quark, Task *task, int arg_size, void *arg_ptr, int arg_flags)
 
unsigned long long QUARK_Insert_Task_Packed (Quark *quark, Task *task)
 
unsigned long long QUARK_Insert_Task (Quark *quark, void(*function)(Quark *), Quark_Task_Flags *task_flags,...)
 
int QUARK_Cancel_Task (Quark *quark, unsigned long long taskid)
 
void QUARK_Worker_Loop (Quark *quark, int thread_rank)
 
Quark_SequenceQUARK_Sequence_Create (Quark *quark)
 
int QUARK_Sequence_Cancel (Quark *quark, Quark_Sequence *sequence)
 
Quark_SequenceQUARK_Sequence_Destroy (Quark *quark, Quark_Sequence *sequence)
 
int QUARK_Sequence_Wait (Quark *quark, Quark_Sequence *sequence)
 
Quark_SequenceQUARK_Get_Sequence (Quark *quark)
 
char * QUARK_Get_Task_Label (Quark *quark)
 
Quark_Task_FlagsQUARK_Task_Flag_Set (Quark_Task_Flags *task_flags, int flag, intptr_t val)
 

Detailed Description

These functions are available from the QUARK library for the scheduling of kernel routines.

Function Documentation

void* QUARK_Args_List ( Quark quark)

Return a pointer to the argument list being processed by the current task and worker.

Parameters
[in]quarkThe scheduler's main data structure.
Returns
Pointer to the current argument list (icl_list_t *)

Definition at line 398 of file quark.c.

References quark_task_s::args_list, worker_s::current_task_ptr, QUARK_Thread_Rank(), and quark_s::worker.

399 {
400  Task *curr_task = quark->worker[QUARK_Thread_Rank(quark)]->current_task_ptr;
401  assert( curr_task != NULL );
402  return (void *)curr_task->args_list;
403 }
int QUARK_Thread_Rank(Quark *quark)
Definition: quark.c:377
struct worker_s ** worker
Definition: quark.c:100
icl_list_t * args_list
Definition: quark.c:147
Quark_Task * current_task_ptr
Definition: quark.c:135

Here is the call graph for this function:

void* QUARK_Args_Pop ( void *  args_list,
void **  last_arg 
)

Return a pointer to the next argument. The variable last_arg should be NULL on the first call, then each subsequent call will used last_arg to get the the next argument. The argument list is not actually popped, it is preservered intact.

Parameters
[in]args_listPointer to the current arguments
[in,out]last_argPointer to the last argument; should be NULL on the first call
Returns
Pointer to the next argument

Definition at line 420 of file quark.c.

References icl_list_s::data, icl_list_first(), and icl_list_next().

421 {
422  icl_list_t *args = (icl_list_t *)args_list;
423  icl_list_t *node = (icl_list_t *)*last_arg;
424  void *arg = NULL;
425  if ( node == NULL ) {
426  node = icl_list_first( args );
427  if (node!=NULL) arg = node->data;
428  } else {
429  node = icl_list_next( args, node );
430  if (node!=NULL) arg = node->data;
431  }
432  *last_arg = node;
433  return arg;
434 }
void * data
Definition: icl_list.h:18
icl_list_t * icl_list_first(icl_list_t *head)
Definition: icl_list.c:192
icl_list_t * icl_list_next(icl_list_t *head, icl_list_t *pos)
Definition: icl_list.c:228

Here is the call graph for this function:

void QUARK_Barrier ( Quark quark)

Called by the master thread. Wait for all the tasks to be completed, then return. The worker tasks will NOT exit from their work loop.

Parameters
[in,out]quarkThe scheduler's main data structure.

Definition at line 771 of file quark.c.

References quark_s::all_tasks_queued, quark_s::num_tasks, process_completed_tasks(), TRUE, work_main_loop(), and quark_s::worker.

772 {
773  quark->all_tasks_queued = TRUE;
774  while ( quark->num_tasks > 0 ) {
776  work_main_loop( quark->worker[0] );
777  }
778 }
struct worker_s ** worker
Definition: quark.c:100
volatile long long num_tasks
Definition: quark.c:105
static void process_completed_tasks(Quark *quark)
Definition: quark.c:2032
static void work_main_loop(Worker *worker)
Definition: quark.c:1732
Definition: quark.c:94
volatile bool all_tasks_queued
Definition: quark.c:104

Here is the call graph for this function:

Here is the caller graph for this function:

int QUARK_Cancel_Task ( Quark quark,
unsigned long long  taskid 
)

Called by any thread. Cancel a task that is in the scheduler. This works by simply making the task a NULL task. The scheduler still processes all the standard dependencies for this task, but when it is time to run the actual function, the scheduler does nothing.

Parameters
[in,out]quarkThe scheduler's main data structure.
[in]taskidThe taskid returned by a QUARK_Insert_Task
Returns
1 on success.
-1 if the task cannot be found (may already be done and removed).
-2 if the task is aready running, done, or cancelled.

Definition at line 1182 of file quark.c.

References CANCELLED, DONE, quark_task_s::function, icl_hash_find(), pthread_mutex_lock_wrap(), pthread_mutex_unlock_wrap(), RUNNING, quark_task_s::status, quark_task_s::task_mutex, quark_s::task_set, and quark_s::task_set_mutex.

1183 {
1185  Task *task = icl_hash_find( quark->task_set, &taskid );
1186  if ( task == NULL ) {
1188  return -1;
1189  }
1192  if ( task->status==RUNNING || task->status==DONE || task->status==CANCELLED ) {
1194  return -2;
1195  }
1196  task->function = NULL;
1198  return 1;
1199 }
pthread_mutex_t task_mutex
Definition: quark.c:142
pthread_mutex_t task_set_mutex
Definition: quark.c:107
void(* function)(Quark *)
Definition: quark.c:143
static int pthread_mutex_unlock_wrap(pthread_mutex_t *mtx)
Definition: quark.c:278
volatile task_status status
Definition: quark.c:144
icl_hash_t * task_set
Definition: quark.c:106
static int pthread_mutex_lock_wrap(pthread_mutex_t *mtx)
Definition: quark.c:277
Definition: quark.c:92
void * icl_hash_find(icl_hash_t *ht, void *key)
Definition: icl_hash.c:105
Definition: quark.c:92

Here is the call graph for this function:

Here is the caller graph for this function:

void QUARK_Delete ( Quark quark)

Called by the master thread. Wait for all tasks to complete, then join/end the worker threads, and clean up all the data structures.

Parameters
[in,out]quarkThe scheduler's main data structure.

Definition at line 846 of file quark.c.

References quark_s::coresbind, quark_s::num_threads, pthread_attr_destroy(), pthread_join(), QUARK_Free(), quark_topology_finalize(), QUARK_Waitall(), quark_s::thread_attr, worker_s::thread_id, and quark_s::worker.

847 {
848  void *exitcodep = NULL;
849  int i;
850 
851  QUARK_Waitall( quark );
852  /* Wait for workers to quit and join threads */
853  for (i = 1; i < quark->num_threads; i++)
854  pthread_join(quark->worker[i]->thread_id, &exitcodep);
856  /* Destroy specific structures */
857  if (quark->coresbind) free(quark->coresbind);
859  /* Destroy hash tables, workers and other data structures */
860  QUARK_Free( quark );
861 }
void QUARK_Waitall(Quark *quark)
Definition: quark.c:790
MAGMA_DLLPORT int MAGMA_CDECL pthread_join(pthread_t thread, void **value_ptr)
struct worker_s ** worker
Definition: quark.c:100
void QUARK_Free(Quark *quark)
Definition: quark.c:809
void quark_topology_finalize()
Definition: quarkos.c:114
int num_threads
Definition: quark.c:99
MAGMA_DLLPORT int MAGMA_CDECL pthread_attr_destroy(pthread_attr_t *attr)
pthread_t thread_id
Definition: quark.c:131
int * coresbind
Definition: quark.c:101
pthread_attr_t thread_attr
Definition: quark.c:110

Here is the call graph for this function:

Here is the caller graph for this function:

void QUARK_Free ( Quark quark)

Called by the master thread. Free all QUARK data structures, this assumes that all usage of QUARK is completed. This interface does not manage, delete or close down the worker threads.

Parameters
[in,out]quarkThe scheduler's main data structure.

Definition at line 809 of file quark.c.

References quark_s::address_set, quark_s::address_set_mutex, quark_s::completed_tasks, quark_s::dot_dag_enable, quark_s::dot_dag_mutex, icl_hash_destroy(), quark_s::num_threads, pthread_mutex_destroy(), QUARK_Waitall(), quark_s::task_set, quark_s::tasklevel_width, tasklevel_width_max_level, quark_s::worker, and worker_delete().

810 {
811  int i;
812  QUARK_Waitall(quark);
813  /* Write the level matching/forcing information */
814  if ( quark->dot_dag_enable ) {
815  for (i=1; i<tasklevel_width_max_level && quark->tasklevel_width[i]!=0; i++ ) {
816  fprintf(dot_dag_file, "%d [label=\"%d:%d\"]\n", i, i, quark->tasklevel_width[i] );
817  fprintf(dot_dag_file, "%d->%d [style=\"invis\"];\n", i-1, i );
818  }
819  fprintf(dot_dag_file, "} \n");
820  }
821  /* Destroy hash tables, workers and other data structures */
822  for (i = 1; i < quark->num_threads; i++)
823  worker_delete( quark->worker[i] );
824  worker_delete( quark->worker[0] );
825  if (quark->worker) free(quark->worker);
826  if (quark->completed_tasks) free(quark->completed_tasks);
827  icl_hash_destroy(quark->address_set, NULL, NULL);
828  icl_hash_destroy(quark->task_set, NULL, NULL);
829  if ( quark->dot_dag_enable ) {
831  fclose(dot_dag_file);
832  }
834  free(quark);
835 }
int tasklevel_width[tasklevel_width_max_level]
Definition: quark.c:118
int icl_hash_destroy(icl_hash_t *ht, void(*free_key)(void *), void(*free_data)(void *))
Definition: icl_hash.c:262
FILE * dot_dag_file
Definition: quark.c:297
pthread_mutex_t address_set_mutex
Definition: quark.c:109
void QUARK_Waitall(Quark *quark)
Definition: quark.c:790
struct worker_s ** worker
Definition: quark.c:100
#define tasklevel_width_max_level
Definition: quark.c:115
icl_hash_t * address_set
Definition: quark.c:108
int dot_dag_enable
Definition: quark.c:116
int num_threads
Definition: quark.c:99
icl_hash_t * task_set
Definition: quark.c:106
struct completed_tasks_head_s * completed_tasks
Definition: quark.c:121
pthread_mutex_t dot_dag_mutex
Definition: quark.c:119
static void worker_delete(Worker *worker)
Definition: quark.c:572
MAGMA_DLLPORT int MAGMA_CDECL pthread_mutex_destroy(pthread_mutex_t *mutex)

Here is the call graph for this function:

Here is the caller graph for this function:

Quark_Sequence* QUARK_Get_Sequence ( Quark quark)

For the current thread, in the current task being executed, return the task's sequence value. This is the value provided when the task was Task_Inserted into a sequence.

Parameters
[in,out]quarkPointer to the scheduler data structure
Returns
Pointer to sequence data structure

Definition at line 1980 of file quark.c.

References worker_s::current_task_ptr, QUARK_Thread_Rank(), quark_task_s::sequence, and quark_s::worker.

1981 {
1982  Task *curr_task = quark->worker[QUARK_Thread_Rank(quark)]->current_task_ptr;
1983  assert( curr_task != NULL);
1984  return (Quark_Sequence *)curr_task->sequence;
1985 }
int QUARK_Thread_Rank(Quark *quark)
Definition: quark.c:377
Quark_Sequence * sequence
Definition: quark.c:157
struct worker_s ** worker
Definition: quark.c:100
Quark_Task * current_task_ptr
Definition: quark.c:135

Here is the call graph for this function:

char* QUARK_Get_Task_Label ( Quark quark)

For the current thread, in the current task being executed, return the task label. This is the value that was optionally provided when the task was Task_Inserted.

Parameters
[in,out]quarkPointer to the scheduler data structure
Returns
Pointer to null-terminated label string
NULL if there is no label

Definition at line 1999 of file quark.c.

References worker_s::current_task_ptr, QUARK_Thread_Rank(), quark_task_s::task_label, and quark_s::worker.

2000 {
2001  Task *curr_task = quark->worker[QUARK_Thread_Rank(quark)]->current_task_ptr;
2002  assert( curr_task != NULL);
2003  return (char *)curr_task->task_label;
2004 }
int QUARK_Thread_Rank(Quark *quark)
Definition: quark.c:377
struct worker_s ** worker
Definition: quark.c:100
char * task_label
Definition: quark.c:154
Quark_Task * current_task_ptr
Definition: quark.c:135

Here is the call graph for this function:

unsigned long long QUARK_Insert_Task ( Quark quark,
void(*)(Quark *)  function,
Quark_Task_Flags task_flags,
  ... 
)

Called by the master thread. Add a new task to the scheduler, providing the data pointers, sizes, and dependency information. This function provides the main user interface for the user to write data-dependent algorithms.

Parameters
[in,out]quarkThe scheduler's main data structure.
[in]functionThe function (task) to be executed by the scheduler
[in]task_flagsFlags to specify task behavior
[in]...Triplets of the form, ending with 0 for arg_size. arg_size, arg_ptr, arg_flags where arg_size: int: Size of the argument in bytes (0 cannot be used here) arg_ptr: pointer: Pointer to data or argument arg_flags: int: Flags indicating argument usage and various decorators INPUT, OUTPUT, INOUT, VALUE, NODEP, SCRATCH LOCALITY, ACCUMULATOR, GATHERV TASK_COLOR, TASK_LABEL (special decorators for VALUE) e.g., arg_flags INPUT | LOCALITY | ACCUMULATOR e.g., arg_flags VALUE | TASK_COLOR
Returns
A long, long integer which can be used to refer to this task (e.g. for cancellation)

Definition at line 1073 of file quark.c.

References QUARK_Insert_Task_Packed(), QUARK_Task_Init(), and QUARK_Task_Pack_Arg().

1074 {
1075  va_list varg_list;
1076  int arg_size;
1077  unsigned long long taskid;
1078 
1079  Task *task = QUARK_Task_Init(quark, function, task_flags);
1080 
1081  va_start(varg_list, task_flags);
1082  // For each argument
1083  while( (arg_size = va_arg(varg_list, int)) != 0) {
1084  void *arg_ptr = va_arg(varg_list, void *);
1085  int arg_flags = va_arg(varg_list, int);
1086  QUARK_Task_Pack_Arg( quark, task, arg_size, arg_ptr, arg_flags );
1087  }
1088  va_end(varg_list);
1089 
1090  taskid = QUARK_Insert_Task_Packed( quark, task );
1091 
1092  return taskid ;
1093 }
void QUARK_Task_Pack_Arg(Quark *quark, Quark_Task *task, int arg_size, void *arg_ptr, int arg_flags)
Definition: quark.c:925
Quark_Task * QUARK_Task_Init(Quark *quark, void(*function)(Quark *), Quark_Task_Flags *task_flags)
Definition: quark.c:895
unsigned long long QUARK_Insert_Task_Packed(Quark *quark, Quark_Task *task)
Definition: quark.c:986

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long long QUARK_Insert_Task_Packed ( Quark quark,
Task task 
)

Called by the master thread. Add a new task to the scheduler, providing the data pointers, sizes, and dependency information. This function provides the main user interface for the user to write data-dependent algorithms.

Parameters
[in,out]quarkThe scheduler's main data structure.
[in,out]taskThe packed task structure that already has all the arguments associated with the function

Definition at line 986 of file quark.c.

References quark_s::address_set_mutex, quark_s::all_tasks_queued, FALSE, quark_task_s::function, quark_s::high_water_mark, icl_hash_insert(), LIST_INSERT_HEAD, quark_s::num_tasks, process_completed_tasks(), pthread_mutex_lock_asn(), pthread_mutex_lock_wrap(), pthread_mutex_unlock_asn(), pthread_mutex_unlock_wrap(), quark_task_s::ptr_to_task_in_sequence, quark_check_and_queue_ready_task(), QUARK_ERR, quark_insert_task_dependencies(), quark_task_s::sequence, Quark_sequence_s::sequence_mutex, Quark_sequence_s::status, quark_s::task_set, quark_s::task_set_mutex, quark_task_s::taskid, Quark_sequence_s::tasks_in_sequence, ll_list_node_s::val, work_main_loop(), and quark_s::worker.

987 {
988  unsigned long long taskid = task->taskid;
989  /* Track sequence information if it is provided */
990  if ( task->sequence ) {
991 /* if ( task->sequence->status == QUARK_ERR ) { */
992 /* task_delete( quark, task ); */
993 /* return QUARK_ERR; */
994 /* } else { */
995 /* ll_list_node_t *entry = malloc(sizeof(ll_list_node_t)); */
996 /* entry->val = task->taskid; */
997 /* ll_list_head_t *headp = task->sequence->tasks_in_sequence; */
998 /* pthread_mutex_lock_wrap( &task->sequence->sequence_mutex ); */
999 /* LIST_INSERT_HEAD( headp, entry, entries ); */
1000 /* pthread_mutex_unlock_wrap( &task->sequence->sequence_mutex ); */
1001 /* /\* Keep pointer to task in sequence so it can be deleted when task completes *\/ */
1002 /* task->ptr_to_task_in_sequence = entry; */
1003 /* printf("sequence %p task %ld addto \n", task->sequence, task->taskid ); */
1004 /* } */
1005  /* TODO FIXME */
1006  if ( task->sequence->status == QUARK_ERR )
1007  task->function = NULL;
1008  ll_list_node_t *entry = malloc(sizeof(ll_list_node_t));
1009  entry->val = task->taskid;
1010  ll_list_head_t *headp = task->sequence->tasks_in_sequence;
1012  LIST_INSERT_HEAD( headp, entry, entries );
1014  /* Keep pointer to task in sequence so it can be deleted when task completes */
1015  task->ptr_to_task_in_sequence = entry;
1016  //printf("sequence %p task %ld addto \n", task->sequence, task->taskid );
1017 
1018  }
1019  /* Insert the task in the address hash, locking access to the address set hash */
1021  /* For repeated usage of the scheduler, if tasks are being added repeatedly
1022  * then quark->finalize and quark->all_tasks_queued must be set false */
1023  quark->all_tasks_queued = FALSE;
1024  quark_insert_task_dependencies( quark, task );
1025  /* FIXME does this need to be protected */
1026  quark->num_tasks++;
1027  /* Save the task, indexed by its taskid */
1029  icl_hash_insert( quark->task_set, &task->taskid, task );
1031  // Check if the task is ready
1032  quark_check_and_queue_ready_task( quark, task );
1034  /* If conditions are right, master works; this will return when
1035  * num_tasks becomes less than low_water_mark */
1036  process_completed_tasks(quark);
1037  while (quark->num_tasks >= quark->high_water_mark) {
1038  work_main_loop(quark->worker[0]);
1039  process_completed_tasks(quark);
1040  }
1041  return taskid ;
1042 }
#define QUARK_ERR
Definition: quark.h:43
pthread_mutex_t address_set_mutex
Definition: quark.c:109
struct ll_list_head_s ll_list_head_t
Definition: quark.c:206
pthread_mutex_t task_set_mutex
Definition: quark.c:107
void(* function)(Quark *)
Definition: quark.c:143
icl_entry_t * icl_hash_insert(icl_hash_t *ht, void *key, void *data)
Definition: icl_hash.c:132
static int pthread_mutex_unlock_asn(pthread_mutex_t *mtx)
Definition: quark.c:271
Definition: quark.c:94
static int pthread_mutex_unlock_wrap(pthread_mutex_t *mtx)
Definition: quark.c:278
static void quark_insert_task_dependencies(Quark *quark, Task *task)
Definition: quark.c:1597
#define LIST_INSERT_HEAD(head, elm, field)
Definition: bsd_queue.h:393
Quark_Sequence * sequence
Definition: quark.c:157
volatile int status
Definition: quark.c:125
struct ll_list_node_s * ptr_to_task_in_sequence
Definition: quark.c:158
struct worker_s ** worker
Definition: quark.c:100
volatile long long num_tasks
Definition: quark.c:105
static void process_completed_tasks(Quark *quark)
Definition: quark.c:2032
static void work_main_loop(Worker *worker)
Definition: quark.c:1732
struct ll_list_head_s * tasks_in_sequence
Definition: quark.c:127
icl_hash_t * task_set
Definition: quark.c:106
static int pthread_mutex_lock_asn(pthread_mutex_t *mtx)
Definition: quark.c:269
static int pthread_mutex_lock_wrap(pthread_mutex_t *mtx)
Definition: quark.c:277
int high_water_mark
Definition: quark.c:98
unsigned long long taskid
Definition: quark.c:151
static void quark_check_and_queue_ready_task(Quark *quark, Task *task)
Definition: quark.c:1258
long long int val
Definition: quark.c:202
pthread_mutex_t sequence_mutex
Definition: quark.c:126
volatile bool all_tasks_queued
Definition: quark.c:104

Here is the call graph for this function:

Here is the caller graph for this function:

Quark* QUARK_New ( int  num_threads)

Called by the master thread. Allocate and initialize the scheduler data stuctures and spawn worker threads. Used when this scheduler is to do all the thread management.

Parameters
[in]num_threadsNumber of threads to be used (1 master and rest compute workers). If num_threads < 1, first try environment variable QUARK_NUM_THREADS or use use num_threads = number of cores
Returns
Pointer to the QUARK data structure.

Definition at line 728 of file quark.c.

References quark_s::coresbind, pthread_attr_init(), pthread_attr_setscope(), pthread_create(), PTHREAD_SCOPE_SYSTEM, quark_get_affthreads(), quark_get_numthreads(), quark_setaffinity(), QUARK_Setup(), quark_topology_init(), quark_s::thread_attr, worker_s::thread_id, work_set_affinity_and_call_main_loop(), and quark_s::worker.

729 {
730  int i, nthrd;
731 
732  /* Init number of cores and topology */
734  /* Get number of threads */
735  if ( num_threads < 1 ) {
736  nthrd = quark_get_numthreads();
737  if ( nthrd == -1 ) {
738  nthrd = 1;
739  }
740  }
741  else
742  nthrd = num_threads;
743 
744  /* Create scheduler data structures for master and workers */
745  Quark *quark = QUARK_Setup(nthrd);
746  /* Get binding informations */
747  quark->coresbind = quark_get_affthreads();
748  /* Setup thread attributes */
750  /* pthread_setconcurrency(quark->num_threads); */
752  /* Then start the threads, so that workers can scan the structures easily */
753  for(i = 1; i < nthrd; i++) {
754  int rc = pthread_create(&quark->worker[i]->thread_id, &quark->thread_attr, (void *(*)(void *))work_set_affinity_and_call_main_loop, quark->worker[i]);
755  assert(rc == 0);
756  }
757  quark_setaffinity( quark->coresbind[0] );
758  return quark;
759 }
Definition: quark.c:96
Quark * QUARK_Setup(int num_threads)
Definition: quark.c:653
MAGMA_DLLPORT int MAGMA_CDECL pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start)(void *), void *arg)
int * quark_get_affthreads()
Definition: quarkos.c:245
int quark_get_numthreads()
Definition: quarkos.c:222
int quark_setaffinity(int rank)
Definition: quarkos.c:125
#define PTHREAD_SCOPE_SYSTEM
struct worker_s ** worker
Definition: quark.c:100
MAGMA_DLLPORT int MAGMA_CDECL pthread_attr_setscope(pthread_attr_t *attr, int scope)
void quark_topology_init()
Definition: quarkos.c:78
static void work_set_affinity_and_call_main_loop(Worker *worker)
Definition: quark.c:1718
pthread_t thread_id
Definition: quark.c:131
int * coresbind
Definition: quark.c:101
pthread_attr_t thread_attr
Definition: quark.c:110
MAGMA_DLLPORT int MAGMA_CDECL pthread_attr_init(pthread_attr_t *attr)

Here is the call graph for this function:

Here is the caller graph for this function:

int QUARK_Sequence_Cancel ( Quark quark,
Quark_Sequence sequence 
)

Can be called by any thread. Cancels all the remaining tasks in a sequence using QUARK_Cancel_Task and changes the state so that future tasks belonging to that sequence are ignored.

Parameters
[in,out]quarkPointer to the scheduler data structure
[in,out]sequencePointer to a sequence data structure
Returns
0 (QUARK_SUCCESS) on success
-1 (QUARK_ERR) on failure

Definition at line 1880 of file quark.c.

References LIST_FOREACH_SAFE, pthread_mutex_lock_wrap(), pthread_mutex_unlock_wrap(), QUARK_Cancel_Task(), QUARK_ERR, QUARK_SUCCESS, Quark_sequence_s::sequence_mutex, Quark_sequence_s::status, Quark_sequence_s::tasks_in_sequence, and ll_list_node_s::val.

1881 {
1882  int retval;
1883  if ( quark==NULL || sequence==NULL ) return QUARK_ERR;
1885  if ( sequence->status != QUARK_SUCCESS ) {
1886  /* sequence already cancelled */
1887  retval = QUARK_SUCCESS;
1888  } else {
1889  sequence->status = QUARK_ERR;
1890  ll_list_node_t *np, *np_temp;
1891  LIST_FOREACH_SAFE( np, sequence->tasks_in_sequence, entries, np_temp ) {
1892  long long int taskid = np->val;
1893  /* Find taskid, make function NULL */
1894  QUARK_Cancel_Task( quark, taskid );
1895  /* Task node is removed from sequence when it finishes and is
1896  * deleted; or when sequence is destroyed */
1897  }
1898  retval = QUARK_SUCCESS;
1899  }
1901  return retval;
1902 }
int QUARK_Cancel_Task(Quark *quark, unsigned long long taskid)
Definition: quark.c:1182
#define QUARK_ERR
Definition: quark.h:43
#define LIST_FOREACH_SAFE(var, head, field, tvar)
Definition: bsd_queue.h:367
static int pthread_mutex_unlock_wrap(pthread_mutex_t *mtx)
Definition: quark.c:278
volatile int status
Definition: quark.c:125
struct ll_list_head_s * tasks_in_sequence
Definition: quark.c:127
static int pthread_mutex_lock_wrap(pthread_mutex_t *mtx)
Definition: quark.c:277
long long int val
Definition: quark.c:202
pthread_mutex_t sequence_mutex
Definition: quark.c:126
#define QUARK_SUCCESS
Definition: quark.h:42

Here is the call graph for this function:

Quark_Sequence* QUARK_Sequence_Create ( Quark quark)

Called by the control program. Creates a new sequence data structure and returns it. This can be used to put a sequence of tasks into a group and cancel that group if an error condition occurs.

Parameters
[in]outquark Pointer to the scheduler data structure
Returns
Pointer to the newly created sequence structure.

Definition at line 1853 of file quark.c.

References LIST_INIT, pthread_mutex_init(), QUARK_SUCCESS, Quark_sequence_s::sequence_mutex, Quark_sequence_s::status, and Quark_sequence_s::tasks_in_sequence.

1854 {
1855  Quark_Sequence *sequence = malloc(sizeof(Quark_Sequence));
1856  assert( sequence != NULL );
1857  sequence->status = QUARK_SUCCESS;
1858  pthread_mutex_init( &sequence->sequence_mutex, NULL );
1859  ll_list_head_t *head = malloc(sizeof(ll_list_head_t));
1860  assert ( head != NULL );
1861  LIST_INIT(head);
1862  sequence->tasks_in_sequence = head;
1863  return sequence;
1864 }
struct ll_list_head_s ll_list_head_t
Definition: quark.c:206
volatile int status
Definition: quark.c:125
struct ll_list_head_s * tasks_in_sequence
Definition: quark.c:127
#define LIST_INIT(head)
Definition: bsd_queue.h:372
MAGMA_DLLPORT int MAGMA_CDECL pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
pthread_mutex_t sequence_mutex
Definition: quark.c:126
#define QUARK_SUCCESS
Definition: quark.h:42

Here is the call graph for this function:

Quark_Sequence* QUARK_Sequence_Destroy ( Quark quark,
Quark_Sequence sequence 
)

Called by the control program. Cancels all the remaining tasks in a sequence using QUARK_Cancel_Task and deletes the sequence data structure.

Parameters
[in,out]quarkPointer to the scheduler data structure
[in,out]sequencePointer to a sequence data structure
Returns
A NULL pointer; which can be used to reset the sequence structure

Definition at line 1917 of file quark.c.

References LIST_FOREACH_SAFE, LIST_REMOVE, pthread_mutex_destroy(), pthread_mutex_lock_wrap(), pthread_mutex_unlock_wrap(), QUARK_Cancel_Task(), QUARK_Sequence_Wait(), Quark_sequence_s::sequence_mutex, Quark_sequence_s::tasks_in_sequence, and ll_list_node_s::val.

1918 {
1919  if ( quark==NULL || sequence==NULL) return NULL;
1920  //printf("QUARK_Sequence_Destroy %p status %d\n", sequence, sequence->status);
1922  ll_list_node_t *np, *np_temp;
1923  ll_list_head_t *head = sequence->tasks_in_sequence;
1924  LIST_FOREACH_SAFE( np, head, entries, np_temp ) {
1925  long long int taskid = np->val;
1926  QUARK_Cancel_Task( quark, taskid );
1927  }
1929  QUARK_Sequence_Wait( quark, sequence );
1931  LIST_FOREACH_SAFE( np, head, entries, np_temp ) {
1932  LIST_REMOVE( np, entries );
1933  free( np );
1934  }
1936  free( head );
1937  head = NULL;
1938  pthread_mutex_destroy( &sequence->sequence_mutex );
1939  free( sequence );
1940  sequence = NULL;
1941  return sequence;
1942 }
int QUARK_Cancel_Task(Quark *quark, unsigned long long taskid)
Definition: quark.c:1182
#define LIST_FOREACH_SAFE(var, head, field, tvar)
Definition: bsd_queue.h:367
struct ll_list_head_s ll_list_head_t
Definition: quark.c:206
static int pthread_mutex_unlock_wrap(pthread_mutex_t *mtx)
Definition: quark.c:278
struct ll_list_head_s * tasks_in_sequence
Definition: quark.c:127
#define LIST_REMOVE(elm, field)
Definition: bsd_queue.h:403
static int pthread_mutex_lock_wrap(pthread_mutex_t *mtx)
Definition: quark.c:277
long long int val
Definition: quark.c:202
MAGMA_DLLPORT int MAGMA_CDECL pthread_mutex_destroy(pthread_mutex_t *mutex)
pthread_mutex_t sequence_mutex
Definition: quark.c:126
int QUARK_Sequence_Wait(Quark *quark, Quark_Sequence *sequence)
Definition: quark.c:1957

Here is the call graph for this function:

int QUARK_Sequence_Wait ( Quark quark,
Quark_Sequence sequence 
)

Called by the control program. Returns when all the tasks in a sequence have completed.

Parameters
[in,out]quarkPointer to the scheduler data structure
[in,out]sequencePointer to a sequence structure
Returns
0 on success
-1 on failure

Definition at line 1957 of file quark.c.

References LIST_EMPTY, process_completed_tasks(), QUARK_ERR, QUARK_SUCCESS, QUARK_Thread_Rank(), Quark_sequence_s::tasks_in_sequence, work_main_loop(), and quark_s::worker.

1958 {
1959  if ( quark==NULL || sequence==NULL) return QUARK_ERR;
1960  int myrank = QUARK_Thread_Rank( quark );
1961  while ( !LIST_EMPTY( sequence->tasks_in_sequence ) ) {
1962  process_completed_tasks( quark );
1963  work_main_loop( quark->worker[myrank] );
1964  }
1965  return QUARK_SUCCESS;
1966 }
#define QUARK_ERR
Definition: quark.h:43
int QUARK_Thread_Rank(Quark *quark)
Definition: quark.c:377
#define LIST_EMPTY(head)
Definition: bsd_queue.h:358
struct worker_s ** worker
Definition: quark.c:100
static void process_completed_tasks(Quark *quark)
Definition: quark.c:2032
static void work_main_loop(Worker *worker)
Definition: quark.c:1732
struct ll_list_head_s * tasks_in_sequence
Definition: quark.c:127
#define QUARK_SUCCESS
Definition: quark.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

Quark* QUARK_Setup ( int  num_threads)

Called by the master thread. This routine does not do thread management, so it can be used with a larger libarary. Allocate and initialize the scheduler data stuctures for the master and num_threads worker threads.

Parameters
[in]num_threadsNumber of threads to be used (1 master and rest compute workers).
Returns
Pointer to the QUARK scheduler data structure.

Definition at line 653 of file quark.c.

References address_hash_function(), address_key_compare(), quark_s::address_set, quark_s::address_set_mutex, quark_s::all_tasks_queued, quark_s::completed_tasks, quark_s::completed_tasks_mutex, quark_s::dot_dag_enable, DOT_DAG_FILENAME, quark_s::dot_dag_mutex, FALSE, fopen, quark_s::high_water_mark, icl_hash_create(), quark_s::list_robin, quark_s::low_water_mark, quark_s::num_queued_tasks, quark_s::num_queued_tasks_cond, quark_s::num_tasks, quark_s::num_threads, pthread_cond_init(), pthread_mutex_init(), pthread_self(), quark_getenv_int(), QUARK_Thread_Rank(), quark_s::queue_before_computing, quark_s::rank, quark_s::start, TAILQ_INIT, quark_s::task_set, quark_s::task_set_mutex, quark_s::tasklevel_width, tasklevel_width_max_level, worker_s::thread_id, TRUE, ullong_hash_function(), ullong_key_compare(), quark_s::war_dependencies_enable, quark_s::worker, and worker_new().

654 {
655  int i = 0;
656  Quark *quark = (Quark *) malloc(sizeof(Quark));
657  assert(quark != NULL);
658  /* Used to tell master when to act as worker */
659  int quark_unroll_tasks_per_thread = quark_getenv_int("QUARK_UNROLL_TASKS_PER_THREAD", 20);
660  int quark_unroll_tasks = quark_getenv_int("QUARK_UNROLL_TASKS", quark_unroll_tasks_per_thread * num_threads);
661  quark->war_dependencies_enable = quark_getenv_int("QUARK_WAR_DEPENDENCIES_ENABLE", 0);
662  quark->queue_before_computing = quark_getenv_int("QUARK_QUEUE_BEFORE_COMPUTING", 0);
663  quark->dot_dag_enable = quark_getenv_int("QUARK_DOT_DAG_ENABLE", 0);
664  if ( quark->dot_dag_enable ) quark->queue_before_computing = 1;
665  if ( quark->queue_before_computing==1 || quark_unroll_tasks==0 ) {
666  quark->high_water_mark = (int)(INT_MAX - 1);
667  quark->low_water_mark = (int)(quark->high_water_mark);
668  } else {
669  quark->low_water_mark = (int)(quark_unroll_tasks);
670  quark->high_water_mark = (int)(quark->low_water_mark + quark->low_water_mark*0.25);
671  }
672  quark->num_queued_tasks = 0;
673  pthread_cond_init( &quark->num_queued_tasks_cond, NULL );
674  quark->num_threads = num_threads;
675  quark->list_robin = 0;
676  quark->start = FALSE;
677  quark->all_tasks_queued = FALSE;
678  quark->num_tasks = 0;
680  pthread_mutex_init( &quark->task_set_mutex, NULL );
681  /* Define some function pointers that match a C++ interface */
682  quark->rank = QUARK_Thread_Rank;
683  /* Create hash table to hold addresses */
685  pthread_mutex_init(&quark->address_set_mutex, NULL);
686  /* To handle completed tasks */
687  quark->completed_tasks = malloc(sizeof(completed_tasks_head_t));
688  assert ( quark->completed_tasks != NULL );
689  TAILQ_INIT( quark->completed_tasks );
691  /* Setup workers */
692  quark->worker = (Worker **) malloc(num_threads * sizeof(Worker *));
693  assert(quark->worker != NULL);
694  /* The structure for the 0th worker will be used by the master */
695  quark->worker[0] = worker_new(quark, 0);
696  quark->worker[0]->thread_id = pthread_self();
697  if ( quark->dot_dag_enable ) {
698  fopen(&dot_dag_file, DOT_DAG_FILENAME, "w"); /* global FILE variable */
699  fprintf(dot_dag_file, "digraph G { size=\"10,7.5\"; center=1; orientation=portrait; \n");
700  for (i=0; i<tasklevel_width_max_level; i++ )
701  quark->tasklevel_width[i] = 0;
702  pthread_mutex_init(&quark->dot_dag_mutex, NULL);
703  /* fprintf(dot_dag_file, "%d [label=\"%d %d\",style=\"invis\"]\n", 0, 0, quark->tasklevel_width[i] ); */
704  fprintf(dot_dag_file, "%d [style=\"invis\"]\n", 0);
705  }
706  /* Launch workers; first create the structures */
707  for(i = 1; i < num_threads; i++)
708  quark->worker[i] = worker_new(quark, i);
709  /* Threads can start as soon as they want */
710  quark->start = TRUE;
711  return quark;
712 }
Definition: quark.c:96
static int ullong_key_compare(void *key1, void *key2)
Definition: quark.c:485
static unsigned int address_hash_function(void *address)
Definition: quark.c:456
int tasklevel_width[tasklevel_width_max_level]
Definition: quark.c:118
FILE * dot_dag_file
Definition: quark.c:297
#define TAILQ_INIT(head)
Definition: bsd_queue.h:503
pthread_mutex_t address_set_mutex
Definition: quark.c:109
pthread_mutex_t task_set_mutex
Definition: quark.c:107
static Worker * worker_new(Quark *quark, int rank)
Definition: quark.c:550
struct completed_tasks_head_s completed_tasks_head_t
Definition: quark.c:214
int QUARK_Thread_Rank(Quark *quark)
Definition: quark.c:377
volatile int list_robin
Definition: quark.c:102
Definition: quark.c:94
static int address_key_compare(void *addr1, void *addr2)
Definition: quark.c:466
#define fopen(ppfile, name, mode)
Definition: quark.c:65
struct worker_s ** worker
Definition: quark.c:100
volatile long long num_tasks
Definition: quark.c:105
volatile int num_queued_tasks
Definition: quark.c:112
volatile bool start
Definition: quark.c:103
#define tasklevel_width_max_level
Definition: quark.c:115
int low_water_mark
Definition: quark.c:97
icl_hash_t * address_set
Definition: quark.c:108
int dot_dag_enable
Definition: quark.c:116
int queue_before_computing
Definition: quark.c:117
int num_threads
Definition: quark.c:99
int war_dependencies_enable
Definition: quark.c:114
icl_hash_t * task_set
Definition: quark.c:106
int high_water_mark
Definition: quark.c:98
MAGMA_DLLPORT int MAGMA_CDECL pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
MAGMA_DLLPORT int MAGMA_CDECL pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Definition: quark.c:94
struct completed_tasks_head_s * completed_tasks
Definition: quark.c:121
pthread_t thread_id
Definition: quark.c:131
int(* rank)()
Definition: quark.c:111
MAGMA_DLLPORT pthread_t MAGMA_CDECL pthread_self(void)
pthread_mutex_t dot_dag_mutex
Definition: quark.c:119
icl_hash_t * icl_hash_create(int nbuckets, unsigned int(*hash_function)(void *), int(*hash_key_compare)(void *, void *))
Definition: icl_hash.c:70
#define DOT_DAG_FILENAME
Definition: quark.c:296
static unsigned int ullong_hash_function(void *key)
Definition: quark.c:475
int quark_getenv_int(char *name, int defval)
Definition: quarkos.c:300
pthread_cond_t num_queued_tasks_cond
Definition: quark.c:113
pthread_mutex_t completed_tasks_mutex
Definition: quark.c:120
volatile bool all_tasks_queued
Definition: quark.c:104

Here is the call graph for this function:

Here is the caller graph for this function:

Quark_Task_Flags* QUARK_Task_Flag_Set ( Quark_Task_Flags task_flags,
int  flag,
intptr_t  val 
)

Set various task level flags. This flag data structure is then provided when the task is created/inserted. Each flag can take a value which is either an integer or a pointer.

     Select from one of the flags:
     TASK_PRIORITY : an integer (0-MAX_INT)
     TASK_LOCK_TO_THREAD : an integer for the thread number
     TASK_LABEL : a string pointer (NULL terminated) for the label
     TASK_COLOR :  a string pointer (NULL terminated) for the color.
     TASK_SEQUENCE : takes pointer to a Quark_Sequence structure
Parameters
[in,out]flagsPointer to a Quark_Task_Flags structure
[in]flagOne of the flags ( TASK_PRIORITY, TASK_LOCK_TO_THREAD, TASK_LABEL, TASK_COLOR, TASK_SEQUENCE )
[in]valA integer or a pointer value for the flag ( uses the intptr_t )
Returns
Pointer to the updated Quark_Task_Flags structure

Definition at line 2145 of file quark.c.

References TASK_COLOR, quark_task_flags_s::task_color, TASK_LABEL, quark_task_flags_s::task_label, TASK_LOCK_TO_THREAD, quark_task_flags_s::task_lock_to_thread, TASK_PRIORITY, quark_task_flags_s::task_priority, TASK_SEQUENCE, quark_task_flags_s::task_sequence, TASK_THREAD_COUNT, and quark_task_flags_s::task_thread_count.

2146 {
2147  switch (flag) {
2148  case TASK_PRIORITY:
2149  task_flags->task_priority = (int)val;
2150  break;
2151  case TASK_LOCK_TO_THREAD:
2152  task_flags->task_lock_to_thread = (int)val;
2153  break;
2154  case TASK_LABEL:
2155  task_flags->task_label = (char *)val;
2156  break;
2157  case TASK_COLOR:
2158  task_flags->task_color = (char *)val;
2159  break;
2160  case TASK_SEQUENCE:
2161  task_flags->task_sequence = (Quark_Sequence *)val;
2162  break;
2163  case TASK_THREAD_COUNT:
2164  task_flags->task_thread_count = (int)val;
2165  break;
2166  }
2167  return task_flags;
2168 }
void * task_sequence
Definition: quark.h:101
#define TASK_LABEL
Definition: quark.h:69
#define TASK_PRIORITY
Definition: quark.h:75
#define TASK_SEQUENCE
Definition: quark.h:79
char * task_label
Definition: quark.h:100
#define TASK_LOCK_TO_THREAD
Definition: quark.h:77
#define TASK_COLOR
Definition: quark.h:72
int task_thread_count
Definition: quark.h:102
#define TASK_THREAD_COUNT
Definition: quark.h:81
char * task_color
Definition: quark.h:99
int task_lock_to_thread
Definition: quark.h:98
int task_priority
Definition: quark.h:97
Task* QUARK_Task_Init ( Quark quark,
void(*)(Quark *)  function,
Quark_Task_Flags task_flags 
)

Called by the master thread. This is used in argument packing, to create an initial task data structure. Arguments can be packed into this structure, and it can be submitted later.

Parameters
[in,out]quarkThe scheduler's main data structure.
[in]functionThe function (task) to be executed by the scheduler
[in]task_flagsFlags to specify task behavior

Definition at line 895 of file quark.c.

References quark_task_s::function, quark_set_task_flags_in_task_structure(), and quark_task_new().

896 {
897  Task *task = quark_task_new();
898  task->function = function;
899  quark_set_task_flags_in_task_structure( quark, task, task_flags );
900  return task;
901 }
void(* function)(Quark *)
Definition: quark.c:143
static Task * quark_task_new()
Definition: quark.c:314
Task * quark_set_task_flags_in_task_structure(Quark *quark, Task *task, Quark_Task_Flags *task_flags)
Definition: quark.c:868

Here is the call graph for this function:

Here is the caller graph for this function:

void QUARK_Task_Pack_Arg ( Quark quark,
Task task,
int  arg_size,
void *  arg_ptr,
int  arg_flags 
)

Called by the master thread. This is used in argument packing, to pack/add arguments to a task data structure.

Parameters
[in,out]quarkThe scheduler's main data structure.
[in,out]taskThe task data struture to hold the arguments
[in]arg_sizeSize of the argument in bytes (0 cannot be used here)
[in]arg_ptrPointer to data or argument
[in]arg_flagsFlags indicating argument usage and various decorators INPUT, OUTPUT, INOUT, VALUE, NODEP, SCRATCH LOCALITY, ACCUMULATOR, GATHERV TASK_COLOR, TASK_LABEL (special decorators for VALUE) e.g., arg_flags INPUT | LOCALITY | ACCUMULATOR e.g., arg_flags VALUE | TASK_COLOR

Definition at line 925 of file quark.c.

References ACCUMULATOR, arg_dup(), quark_task_s::args_list, quark_task_s::dependency_list, dependency_new(), DIRECTION_MASK, quark_s::dot_dag_enable, GATHERV, icl_list_append(), INOUT, INPUT, LOCALITY, quark_task_s::lock_to_thread, quark_task_s::num_dependencies, quark_task_s::num_dependencies_remaining, OUTPUT, quark_task_s::priority, SCRATCH, quark_task_s::scratch_list, scratch_new(), quark_task_s::sequence, TASK_COLOR, quark_task_s::task_color, dependency_s::task_dependency_list_node_ptr, TASK_LABEL, quark_task_s::task_label, TASK_LOCK_TO_THREAD, TASK_PRIORITY, TASK_SEQUENCE, TASK_THREAD_COUNT, quark_task_s::task_thread_count, and VALUE.

926 {
927  icl_list_t *task_args_list_node_ptr=NULL;
928  // extract information from the flags
929  bool arg_locality = (bool) ((arg_flags & LOCALITY) != 0 );
930  bool accumulator = (bool) ((arg_flags & ACCUMULATOR) != 0 );
931  bool gatherv = (bool) ((arg_flags & GATHERV) != 0 );
932  bool task_priority = (bool) ((arg_flags & TASK_PRIORITY) != 0 );
933  bool task_lock_to_thread = (bool) ((arg_flags & TASK_LOCK_TO_THREAD) != 0 );
934  bool task_thread_count = (bool) ((arg_flags & TASK_THREAD_COUNT) != 0 );
935  bool task_color = (bool) ((arg_flags & TASK_COLOR) != 0 );
936  bool task_label = (bool) ((arg_flags & TASK_LABEL) != 0 );
937  bool task_sequence = (bool) ((arg_flags & TASK_SEQUENCE) != 0 );
938  quark_direction_t arg_direction = (quark_direction_t) (arg_flags & DIRECTION_MASK);
939  if (arg_direction == VALUE) {
940  /* If argument is a value; Copy the contents to the argument buffer */
941  if ( task_priority ) task->priority = *((int *)arg_ptr);
942  else if ( task_lock_to_thread ) task->lock_to_thread = *((int *)arg_ptr);
943  else if ( task_thread_count ) task->task_thread_count = *((int *)arg_ptr);
944  else if ( task_sequence ) task->sequence = *((Quark_Sequence **)arg_ptr);
945  else if ( task_color && quark->dot_dag_enable ) {
946  if ( task->task_color && task->task_color!=quark_task_default_color) free(task->task_color);
947  task->task_color = arg_dup(arg_ptr, arg_size);
948  }
949  else if ( task_label && quark->dot_dag_enable ) {
950  if ( task->task_label && task->task_label!=quark_task_default_label) free(task->task_label);
951  task->task_label = arg_dup(arg_ptr, arg_size) ;
952  }
953  else task_args_list_node_ptr = icl_list_append(task->args_list, arg_dup(arg_ptr, arg_size));
954  } else {
955  /* Else - argument is a pointer; Copy the pointer to the argument buffer - pass by reference */
956  task_args_list_node_ptr = icl_list_append(task->args_list, arg_dup((char *) &arg_ptr, sizeof(char *)));
957  }
958  if ((arg_ptr != NULL) && ( arg_direction==INPUT || arg_direction==INOUT || arg_direction==OUTPUT )) {
959  /* If argument is a dependency/slice, add dependency to task dependency list */
960  Dependency *dep = dependency_new(arg_ptr, arg_size, arg_direction, arg_locality, task, accumulator, gatherv, task_args_list_node_ptr);
961  icl_list_t *task_dependency_list_node_ptr = icl_list_append( task->dependency_list, dep );
962  dep->task_dependency_list_node_ptr = task_dependency_list_node_ptr;
963  task->num_dependencies++;
965  }
966  else if( arg_direction==SCRATCH ) {
967  Scratch *scratch = scratch_new( arg_ptr, arg_size, task_args_list_node_ptr);
968  icl_list_append( task->scratch_list, scratch );
969  }
970 }
volatile int num_dependencies_remaining
Definition: quark.c:146
Definition: quark.h:52
int task_thread_count
Definition: quark.c:159
#define TASK_LABEL
Definition: quark.h:69
#define TASK_PRIORITY
Definition: quark.h:75
quark_direction_t
Definition: quark.h:52
int lock_to_thread
Definition: quark.c:153
#define TASK_SEQUENCE
Definition: quark.h:79
icl_list_t * icl_list_append(icl_list_t *head, void *data)
Definition: icl_list.c:304
#define TASK_LOCK_TO_THREAD
Definition: quark.h:77
Definition: quark.h:52
Quark_Sequence * sequence
Definition: quark.c:157
#define LOCALITY
Definition: quark.h:56
icl_list_t * task_dependency_list_node_ptr
Definition: quark.c:173
#define ACCUMULATOR
Definition: quark.h:60
#define DIRECTION_MASK
Definition: quark.c:91
#define TASK_COLOR
Definition: quark.h:72
int priority
Definition: quark.c:156
char * task_label
Definition: quark.c:154
int dot_dag_enable
Definition: quark.c:116
icl_list_t * args_list
Definition: quark.c:147
static char * quark_task_default_label
Definition: quark.c:291
#define TASK_THREAD_COUNT
Definition: quark.h:81
char * task_color
Definition: quark.c:155
icl_list_t * scratch_list
Definition: quark.c:149
#define INPUT
Definition: quark.h:53
Definition: quark.h:52
volatile int num_dependencies
Definition: quark.c:145
static Dependency * dependency_new(void *addr, long long size, quark_direction_t dir, bool loc, Task *task, bool accumulator, bool gatherv, icl_list_t *task_args_list_node_ptr)
Definition: quark.c:521
Definition: quark.h:52
#define GATHERV
Definition: quark.h:64
static Scratch * scratch_new(void *arg_ptr, int arg_size, icl_list_t *task_args_list_node_ptr)
Definition: quark.c:591
static char * arg_dup(char *arg, int size)
Definition: quark.c:509
bool
Definition: quark.c:94
icl_list_t * dependency_list
Definition: quark.c:148
static char * quark_task_default_color
Definition: quark.c:292

Here is the call graph for this function:

Here is the caller graph for this function:

void QUARK_Waitall ( Quark quark)

Called by the master thread. Wait for all the tasks to be completed, then return. The worker tasks will also exit from their work loop at this time.

Parameters
[in,out]quarkThe scheduler's main data structure.

Definition at line 790 of file quark.c.

References worker_s::finalize, quark_s::num_threads, QUARK_Barrier(), TRUE, and quark_s::worker.

791 {
792  int i;
793  QUARK_Barrier( quark );
794  /* Tell each worker to exit the work_loop; master handles himself */
795  for (i=1; i<quark->num_threads; i++)
796  quark->worker[i]->finalize = TRUE;
797 }
struct worker_s ** worker
Definition: quark.c:100
int num_threads
Definition: quark.c:99
volatile bool finalize
Definition: quark.c:137
Definition: quark.c:94
void QUARK_Barrier(Quark *quark)
Definition: quark.c:771

Here is the call graph for this function:

Here is the caller graph for this function:

void QUARK_Worker_Loop ( Quark quark,
int  thread_rank 
)

This function is called by a thread when it wants to start working. This is used in a system that does its own thread management, so each worker thread in that system must call this routine to get the worker to participate in computation.

Parameters
[in,out]quarkThe main data structure.
[in]thread_rankThe rank of the thread.

Definition at line 1702 of file quark.c.

References pthread_self(), worker_s::thread_id, work_main_loop(), and quark_s::worker.

1703 {
1704  quark->worker[thread_rank]->thread_id = pthread_self();
1705  work_main_loop( quark->worker[thread_rank] );
1706 }
struct worker_s ** worker
Definition: quark.c:100
static void work_main_loop(Worker *worker)
Definition: quark.c:1732
pthread_t thread_id
Definition: quark.c:131
MAGMA_DLLPORT pthread_t MAGMA_CDECL pthread_self(void)

Here is the call graph for this function: