PULSAR  0.1
Parallel Unified Linear Algebra with Systolic Arrays
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
prt_channel.c
Go to the documentation of this file.
1 
11 #include "prt_channel.h"
12 
14 
27  int count, MPI_Datatype datatype,
28  int *src_tuple, int src_slot,
29  int *dst_tuple, int dst_slot)
30 {
31  // Allocate the channel.
32  prt_channel_t *channel = (prt_channel_t*)malloc(sizeof(prt_channel_t));
33  prt_assert(channel != NULL, "malloc failed");
34 
35  // Check parameters.
36  prt_assert(count > 0, "count less or equal zero");
37  prt_assert(src_tuple != NULL, "NULL source tuple");
38  prt_assert(src_tuple != NULL, "NULL destination tuple");
39 
40  // Initialize the channel.
41  channel->vdp = NULL;
42  channel->count = count;
43  channel->datatype = datatype;
44  channel->src_tuple = src_tuple;
45  channel->dst_tuple = dst_tuple;
46  channel->src_slot = src_slot;
47  channel->dst_slot = dst_slot;
48 
49  // Create the list of packets.
50  channel->packets = icl_deque_new();
51  prt_assert(channel->packets != NULL, "icl_deque_new() failed");
52 //printf("new\n"); fflush(stdout);
53  // Return the channel.
54  return channel;
55 }
56 
58 
64 {
65  // Check for a NULL channel.
66  prt_assert(channel != NULL, "NULL channel");
67 
68  // Free the source tuple.
69  prt_assert(channel->src_tuple != NULL, "NULL tuple");
70  free(channel->src_tuple);
71 
72  // Free the destination tuple.
73  prt_assert(channel->dst_tuple != NULL, "NULL tuple");
74  free(channel->dst_tuple);
75 
76  // Destroy the list of packets.
77  // Only an empty list can be destroyed.
78  // Therefore NULL given as the packet destructor.
79  prt_assert(channel->packets != NULL, "NULL packets list");
80  int size = icl_deque_size(channel->packets);
81  prt_assert(size == 0, "non-epty packet list");
82  icl_deque_destroy(channel->packets, NULL);
83 //printf("delete\n"); fflush(stdout);
84  // Free the channel.
85  free(channel);
86 }
87 
89 
97 {
98  // Check for a NULL input params.
99  prt_assert(packet != NULL, "NULL packet");
100  prt_assert(channel != NULL, "NULL channel");
101  prt_assert(channel->packets != NULL, "NULL packet list");
102 
103  __sync_fetch_and_add(&packet->num_refs, 1);
104  icl_deque_append(channel->packets, (void*)packet);
105 
106  // IF a dangling channel.
107  if (channel->dst_node != channel->vdp->thread->vsa->node_rank)
108  // Notify the proxy.
110  channel->vdp->thread->vsa->proxy,
111  channel->vdp->thread->rank,
112  channel);
113 }
114 
116 
126 {
127  // Check for a NULL input params.
128  prt_assert(channel != NULL, "popping from a NULL channel");
129  prt_assert(channel->packets != NULL, "popping from a NULL packet list");
130 
131  icl_node_t *node = icl_deque_first(channel->packets);
132  prt_assert(node != NULL, "empty packet list");
133 
134  prt_packet_t *packet = (prt_packet_t*)node->data;
135  prt_assert(packet != NULL, "NULL packet");
136 
137  icl_deque_delete(channel->packets, node, NULL);
138  return packet;
139 }
140 
142 
151 {
152  // Check for a NULL input params.
153  prt_assert(channel != NULL, "NULL channel");
154  prt_assert(channel->packets != NULL, "NULL packet list");
155 
156  // Return the status.
157  return (icl_deque_first(channel->packets) == NULL);
158 }
159 
161 
171 int prt_channel_compare(void *channel1, void *channel2)
172 {
173  prt_channel_t *c1 = (prt_channel_t*)channel1;
174  prt_channel_t *c2 = (prt_channel_t*)channel2;
175  if (prt_tuple_compare(c1->src_tuple, c2->src_tuple) != 0) return 1;
176  if (prt_tuple_compare(c1->dst_tuple, c2->dst_tuple) != 0) return 1;
177  if (c1->src_slot != c2->src_slot) return 1;
178  if (c1->dst_slot != c2->dst_slot) return 1;
179  return 0;
180 }
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:38
int prt_tuple_compare(void *tuple_a, void *tuple_b)
tuple comparison
Definition: prt_tuple.c:135
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:125
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's data packet A packet of data transferred through VDP's channels.
Definition: prt_packet.h:24
int * dst_tuple
Definition: prt_channel.h:35
void prt_channel_push(prt_channel_t *channel, prt_packet_t *packet)
Sends a packed down a channel. Increments the packet's number of active references.
Definition: prt_channel.c:96
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:150
void prt_channel_delete(prt_channel_t *channel)
channel destructor
Definition: prt_channel.c:63
int icl_deque_destroy(icl_deque_t *deque, void(*free_func)(void *))
deque destructor
Definition: icl_deque.c:53
VDP's data channel Implements a data link between a pair of VDPs. Identifies the source and destinati...
Definition: prt_channel.h:29
int prt_channel_compare(void *channel1, void *channel2)
Compare two channels. Channels are equal if they have the same source and destination tuples and slot...
Definition: prt_channel.c:171
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
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:26
struct prt_thread_s * thread
Definition: prt_vdp.h:38
struct prt_proxy_s * proxy
Definition: prt_vsa.h:56
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