PULSAR  1.0.0
Parallel Ultra Light Systolic Array Runtime
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
prt_thread.c File Reference

PRT thread implementation. More...

#include "prt_thread.h"
Include dependency graph for prt_thread.c:

Go to the source code of this file.

Functions

prt_thread_tprt_thread_new (int rank, int core)
 thread object constructor More...
 
void prt_thread_delete (prt_thread_t *thread)
 thread object destructor More...
 
void * prt_thread_run (void *thrd)
 thread's production cycle Cycle through VDPs. Fire the ones that are ready. Remove the ones which burned out. Return when the list of VDPs becomes empty. More...
 

Detailed Description

PRT thread implementation.

Author
Jakub Kurzak

PULSAR Runtime http://icl.eecs.utk.edu/pulsar/ Copyright (C) 2012-2013 University of Tennessee.

Definition in file prt_thread.c.

Function Documentation

void prt_thread_delete ( prt_thread_t thread)

thread object destructor

Parameters
thread

Definition at line 48 of file prt_thread.c.

References icl_list_destroy(), icl_list_size(), prt_assert, and prt_thread_s::vdps.

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 }
int icl_list_size(icl_list_t *head)
Get the number of items in this linked list.
Definition: icl_list.c:200
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
icl_list_t * vdps
Definition: prt_thread.h:32
#define prt_assert(cond, msg)
Definition: prt_assert.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

prt_thread_t* prt_thread_new ( int  rank,
int  core 
)

thread object constructor

Parameters
ranklocal thread rank
coreglobal core number
Returns
new thread object

Definition at line 22 of file prt_thread.c.

References prt_thread_s::core, prt_thread_s::finished, icl_list_new(), prt_assert, prt_thread_s::rank, and prt_thread_s::vdps.

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 }
icl_list_t * icl_list_new()
Create new linked list.
Definition: icl_list.c:23
icl_list_t * vdps
Definition: prt_thread.h:32
#define prt_assert(cond, msg)
Definition: prt_assert.h:30
VSA's worker thread Owns a number of VDPs. Knows the communication proxy.
Definition: prt_thread.h:27

Here is the call graph for this function:

Here is the caller graph for this function:

void* prt_thread_run ( void *  thrd)

thread's production cycle Cycle through VDPs. Fire the ones that are ready. Remove the ones which burned out. Return when the list of VDPs becomes empty.

Parameters
thrdpointer to the thread object

Definition at line 70 of file prt_thread.c.

References prt_vdp_s::color, prt_vsa_s::config, prt_vdp_s::counter, icl_list_s::data, prt_thread_s::finished, prt_vdp_s::function, prt_vsa_s::global_store, icl_list_delete(), icl_list_first(), icl_list_next(), prt_vdp_s::input, prt_vdp_s::local_store, prt_vdp_s::output, prt_vdp_ready(), PRT_VDP_SCHEDULING_AGGRESSIVE, PRT_VDP_SCHEDULING_LAZY, prt_thread_s::rank, svg_trace_start(), svg_trace_stop(), prt_vdp_s::tuple, prt_config_s::vdp_scheduling, prt_thread_s::vdps, and prt_thread_s::vsa.

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
struct prt_channel_s ** input
Definition: prt_vdp.h:42
void * data
Definition: icl_list.h:20
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 * local_store
Definition: prt_vdp.h:46
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
void * global_store
Definition: prt_vsa.h:52
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
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

Here is the call graph for this function:

Here is the caller graph for this function: