PULSAR  1.0.0
Parallel Ultra Light Systolic Array Runtime
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
prt_channel.c
Go to the documentation of this file.
1 
11 #include "prt_channel.h"
12 
14 
28  int count, MPI_Datatype datatype,
29  int *src_tuple, int src_slot,
30  int *dst_tuple, int dst_slot)
31 {
32  // Allocate the channel.
33  prt_channel_t *channel = (prt_channel_t*)malloc(sizeof(prt_channel_t));
34  prt_assert(channel != NULL, "malloc failed");
35 
36  // Check parameters.
37  prt_assert(count > 0, "count less or equal zero");
38  prt_assert(src_tuple != NULL, "NULL source tuple");
39  prt_assert(src_tuple != NULL, "NULL destination tuple");
40 
41  // Initialize the channel.
42  channel->vdp = NULL;
43  channel->count = count;
44  channel->datatype = datatype;
45  channel->src_tuple = src_tuple;
46  channel->dst_tuple = dst_tuple;
47  channel->src_slot = src_slot;
48  channel->dst_slot = dst_slot;
49 
50  // Create the list of packets.
51  channel->packets = icl_deque_new();
52  prt_assert(channel->packets != NULL, "icl_deque_new() failed");
53 
54  // Return the channel.
55  return channel;
56 }
57 
59 
65 {
66  // Check for a NULL channel.
67  prt_assert(channel != NULL, "NULL channel");
68 
69  // Free the source tuple.
70  prt_assert(channel->src_tuple != NULL, "NULL tuple");
71  free(channel->src_tuple);
72 
73  // Free the destination tuple.
74  prt_assert(channel->dst_tuple != NULL, "NULL tuple");
75  free(channel->dst_tuple);
76 
77  // Destroy the list of packets.
78  // Only an empty list can be destroyed.
79  // Therefore NULL given as the packet destructor.
80  prt_assert(channel->packets != NULL, "NULL packets list");
81  int size = icl_deque_size(channel->packets);
82  prt_assert(size == 0, "non-epty packet list");
83  icl_deque_destroy(channel->packets, NULL);
84 
85  // Free the channel.
86  free(channel);
87 }
88 
90 
99 {
100  // Check for a NULL input params.
101  prt_assert(packet != NULL, "NULL packet");
102  prt_assert(channel != NULL, "NULL channel");
103  prt_assert(channel->packets != NULL, "NULL packet list");
104 
105  __sync_fetch_and_add(&packet->num_refs, 1);
106  icl_deque_append(channel->packets, (void*)packet);
107 
108  // IF a dangling channel.
109  if (channel->dst_node != channel->vdp->thread->vsa->node_rank)
110  // Notify the proxy.
112  channel->vdp->thread->vsa->proxy,
113  channel->vdp->thread->rank,
114  channel);
115 }
116 
118 
129 {
130  // Check for a NULL input params.
131  prt_assert(channel != NULL, "popping from a NULL channel");
132  prt_assert(channel->packets != NULL, "popping from a NULL packet list");
133 
134  icl_node_t *node = icl_deque_first(channel->packets);
135  prt_assert(node != NULL, "empty packet list");
136 
137  prt_packet_t *packet = (prt_packet_t*)node->data;
138  prt_assert(packet != NULL, "NULL packet");
139 
140  icl_deque_delete(channel->packets, node, NULL);
141  return packet;
142 }
143 
145 
154 {
155  // Check for a NULL input params.
156  prt_assert(channel != NULL, "NULL channel");
157  prt_assert(channel->packets != NULL, "NULL packet list");
158 
159  // Return the status.
160  return (icl_deque_first(channel->packets) == NULL);
161 }
162 
164 
174 int prt_channel_compare(void *channel1, void *channel2)
175 {
176  prt_channel_t *c1 = (prt_channel_t*)channel1;
177  prt_channel_t *c2 = (prt_channel_t*)channel2;
178 
179  if (prt_tuple_compare(c1->src_tuple, c2->src_tuple) != 0)
180  return prt_tuple_compare(c1->src_tuple, c2->src_tuple);
181 
182  if (c1->src_slot < c2->src_slot) return -1;
183  if (c1->src_slot > c2->src_slot) return 1;
184 
185  if (prt_tuple_compare(c1->dst_tuple, c2->dst_tuple) != 0)
186  return prt_tuple_compare(c1->dst_tuple, c2->dst_tuple);
187 
188  if (c1->dst_slot < c2->dst_slot) return -1;
189  if (c1->dst_slot > c2->dst_slot) return 1;
190 
191  return 0;
192 }
icl_node_t * icl_deque_append(icl_deque_t *deque, void *data)
Insert the node at the end of the deque.
Definition: icl_deque.c:118
icl_deque_t * packets
Definition: prt_channel.h:40
int prt_tuple_compare(void *tuple_a, void *tuple_b)
tuple comparison
Definition: prt_tuple.c:135
void * data
Definition: icl_list.h:20
icl_deque_t * icl_deque_new()
deque constructor
Definition: icl_deque.c:23
MPI_Datatype datatype
Definition: prt_channel.h:32
int icl_deque_size(icl_deque_t *deque)
Return the deque size.
Definition: icl_deque.c:189
PRT data channel.
icl_node_t * icl_deque_first(icl_deque_t *deque)
Get the first node in the deque.
Definition: icl_deque.c:76
struct prt_vsa_s * vsa
Definition: prt_thread.h:28
VDP&#39;s data packet A packet of data transferred through VDP&#39;s channels.
Definition: prt_packet.h:24
void prt_channel_push(prt_channel_t *channel, prt_packet_t *packet)
Sends a packed down a channel. Increments the packet&#39;s number of active references.
Definition: prt_channel.c:98
int * dst_tuple
Definition: prt_channel.h:35
int * src_tuple
Definition: prt_channel.h:33
int prt_channel_empty(prt_channel_t *channel)
Checks if a channel is empty.
Definition: prt_channel.c:153
void prt_channel_delete(prt_channel_t *channel)
channel destructor
Definition: prt_channel.c:64
int icl_deque_destroy(icl_deque_t *deque, void(*free_func)(void *))
deque destructor
Definition: icl_deque.c:53
VDP&#39;s data channel Implements a data link between a pair of VDPs. Identifies the source and destinati...
Definition: prt_channel.h:29
prt_packet_t * prt_channel_pop(prt_channel_t *channel)
Fetches a packef from a channel. Does not decrement the number of active references. The packet leaves the channel, but enters the VDP.
Definition: prt_channel.c:128
int prt_channel_compare(void *channel1, void *channel2)
Compare two channels.
Definition: prt_channel.c:174
int icl_deque_delete(icl_deque_t *deque, icl_node_t *node, void(*free_func)(void *))
Delete the node from the deque.
Definition: icl_deque.c:164
int node_rank
Definition: prt_vsa.h:46
#define prt_assert(cond, msg)
Definition: prt_assert.h:30
struct prt_thread_s * thread
Definition: prt_vdp.h:38
struct prt_proxy_s * proxy
Definition: prt_vsa.h:56
prt_channel_t * prt_channel_new(int count, MPI_Datatype datatype, int *src_tuple, int src_slot, int *dst_tuple, int dst_slot)
channel constructor
Definition: prt_channel.c:27
struct prt_vdp_s * vdp
Definition: prt_channel.h:30
void prt_proxy_send(prt_proxy_t *proxy, int thread_rank, prt_channel_t *channel)
send from a channel
Definition: prt_proxy.c:122