PULSAR  1.0.0
Parallel Ultra Light Systolic Array Runtime
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
prt_thread.c
Go to the documentation of this file.
1 
11 #include "prt_thread.h"
12 
14 
22 prt_thread_t* prt_thread_new(int rank, int core)
23 {
24  // Allocate the thread.
25  prt_thread_t *thread = (prt_thread_t*)malloc(sizeof(prt_thread_t));
26  prt_assert(thread != NULL, "malloc failed");
27 
28  // Initialize the thread.
29  thread->rank = rank;
30  thread->core = core;
31  thread->finished = 0;
32 
33  // Create the list of VDPs.
34  // No error checking.
35  thread->vdps = icl_list_new();
36  prt_assert(thread->vdps != NULL, "icl_list_new failed");
37 
38  // Return the thread.
39  return thread;
40 }
41 
43 
49 {
50  // Destroy the list of VDPs.
51  int size = icl_list_size(thread->vdps);
52  prt_assert(size == 0, "destroying non-empty list");
53  int status = icl_list_destroy(thread->vdps, NULL);
54  prt_assert(status == 0, "icl_list_destroy failed");
55 
56  // Free the thread.
57  free(thread);
58 }
59 
61 
70 void* prt_thread_run(void *thrd)
71 {
72  prt_thread_t *thread = (prt_thread_t*)thrd;
73  icl_list_t *prev;
74  icl_list_t *node;
75  icl_list_t *next;
76  // WHILE the list of VDPs not empty.
77  while ((node = icl_list_first(thread->vdps)) != NULL) {
78  // REPEAT.
79  do {
80  prt_vdp_t *vdp = (prt_vdp_t*)node->data;
82  // WHILE inputs ready AND counter NOT zero.
83  while (vdp->counter > 0 && prt_vdp_ready(vdp)) {
84  // Fire and decrement.
85  svg_trace_start(thread->rank+1);
86  vdp->function(
87  vdp->tuple, vdp->counter,
88  vdp->input, vdp->output,
89  vdp->local_store, thread->vsa->global_store);
90  svg_trace_stop(thread->rank+1, vdp->color);
91  vdp->counter--;
92  }
93  }
94  else if (thread->vsa->config->vdp_scheduling == PRT_VDP_SCHEDULING_LAZY) {
95  // IF inputs ready AND counter NOT zero.
96  if (vdp->counter > 0 && prt_vdp_ready(vdp)) {
97  // Fire and decrement.
98  svg_trace_start(thread->rank+1);
99  vdp->function(
100  vdp->tuple, vdp->counter,
101  vdp->input, vdp->output,
102  vdp->local_store, thread->vsa->global_store);
103  svg_trace_stop(thread->rank+1, vdp->color);
104  vdp->counter--;
105  }
106  }
107  prev = node;
108  node = icl_list_next(thread->vdps, node);
109  // IF counter zeroed.
110  if (vdp->counter == 0)
111  // Remove the VDP from the list
112  // Do not destroy the VDP itself.
113  icl_list_delete(thread->vdps, prev, NULL);
114  }
115  while (node != NULL);
116  // UNTIL the end of the list.
117  }
118  // Signal completion.
119  thread->finished = 1;
120 }
int color
Definition: prt_vdp.h:47
prt_vdp_function_t function
Definition: prt_vdp.h:45
icl_list_t * icl_list_new()
Create new linked list.
Definition: icl_list.c:23
int icl_list_size(icl_list_t *head)
Get the number of items in this linked list.
Definition: icl_list.c:200
struct prt_channel_s ** input
Definition: prt_vdp.h:42
void * data
Definition: icl_list.h:20
int icl_list_destroy(icl_list_t *head, void(*free_function)(void *))
Frees the resources associated with this linked list.
Definition: icl_list.c:173
struct prt_config_s * config
Definition: prt_vsa.h:55
struct prt_vsa_s * vsa
Definition: prt_thread.h:28
icl_list_t * icl_list_first(icl_list_t *head)
Get the first item in this linked list.
Definition: icl_list.c:221
int prt_vdp_ready(prt_vdp_t *vdp)
Check if a VDP is ready to fire. Only checks established channels. (NULL channels don't prevent firin...
Definition: prt_vdp.c:225
void * prt_thread_run(void *thrd)
thread's production cycle Cycle through VDPs. Fire the ones that are ready. Remove the ones which bur...
Definition: prt_thread.c:70
void * local_store
Definition: prt_vdp.h:46
void prt_thread_delete(prt_thread_t *thread)
thread object destructor
Definition: prt_thread.c:48
void svg_trace_start(int thread_rank)
Start tracing an event.
Definition: svg_trace.c:50
int counter
Definition: prt_vdp.h:40
icl_list_t * vdps
Definition: prt_thread.h:32
prt_thread_t * prt_thread_new(int rank, int core)
thread object constructor
Definition: prt_thread.c:22
void * global_store
Definition: prt_vsa.h:52
#define prt_assert(cond, msg)
Definition: prt_assert.h:30
Virtual Data Processor (VDP) Is uniquely identified by a tuple. Fires for a predefined number of cycl...
Definition: prt_vdp.h:37
int icl_list_delete(icl_list_t *head, icl_list_t *pos, void(*free_function)(void *))
Delete the specified node.
Definition: icl_list.c:83
VSA's worker thread Owns a number of VDPs. Knows the communication proxy.
Definition: prt_thread.h:27
void svg_trace_stop(int thread_rank, int color)
Stop tracing an event.
Definition: svg_trace.c:63
struct prt_channel_s ** output
Definition: prt_vdp.h:44
PRT thread.
int * tuple
Definition: prt_vdp.h:39
int vdp_scheduling
Definition: prt_config.h:42
icl_list_t * icl_list_next(icl_list_t *head, icl_list_t *pos)
Get the node following the specified node.
Definition: icl_list.c:254