5
/* begin_generated_IBM_copyright_prolog */
7
/* ---------------------------------------------------------------- */
8
/* (C)Copyright IBM Corp. 2007, 2008 */
10
/* ---------------------------------------------------------------- */
12
/* end_generated_IBM_copyright_prolog */
14
* \file armci/src/armcix/dcmf/armcix_rmw.c
15
* \brief DCMF ARMCI Extension for rmw operations.
18
#include "armcix_impl.h"
23
typedef union ARMCIX_DCMF_RMWRequest_t
35
ARMCIX_DCMF_RMWRequest_t __attribute__ ((__aligned__ (16)));
37
typedef union ARMCIX_DCMF_RMWResponse_t
52
ARMCIX_DCMF_RMWResponse_t __attribute__ ((__aligned__ (16)));
55
DCMF_Protocol_t __rmw_request_protocol;
56
DCMF_Protocol_t __rmw_response_protocol;
60
void ARMCIX_DCMF_RecvRMWRequest (void * clientdata,
61
const DCQuad * msginfo,
67
ARMCIX_DCMF_RMWRequest_t * info = (ARMCIX_DCMF_RMWRequest_t *) msginfo;
69
/* Initialize the RMW response data */
70
ARMCIX_DCMF_RMWResponse_t response;
71
response.op = info->op;
72
response.ploc = info->ploc;
73
response.active = info->active;
75
//fprintf (stderr, "ARMCIX_DCMF_RecvRMWRequest() - info->op == %d, info->ploc == %p, info->prem == %p, info->extra == %d, peer == %d\n", info->op, info->ploc, info->prem, info->extra, peer);
79
case ARMCI_FETCH_AND_ADD:
81
response.ival = *((int *) info->prem);
83
case ARMCI_FETCH_AND_ADD_LONG:
85
response.lval = *((long *) info->prem);
88
armci_die("rmw: operation not supported",info->op);
92
/* Send the rmw response. */
93
DCMF_Control (&__rmw_response_protocol,
94
DCMF_SEQUENTIAL_CONSISTENCY,
96
(DCMF_Control_t *) &response);
98
/* Perform the swap or add */
101
case ARMCI_FETCH_AND_ADD:
102
*((int *) info->prem) += info->extra;
104
case ARMCI_FETCH_AND_ADD_LONG:
105
*((long *) info->prem) += info->extra;
108
*((int *) info->prem) = info->extra;
110
case ARMCI_SWAP_LONG:
111
*((long *) info->prem) = info->extra;
114
armci_die("rmw: operation not supported",info->op);
120
* \brief Receive a read-modify-write response message.
122
* \param[in] clientdata Registered clientdata
123
* \param[in] info Read-Modify-Write data sent from the target node
124
* \param[in] peer Rank of the node that sent this control message
126
* \see ARMCIX_DCMF_Connection_t
127
* \see ARMCIX_DCMF_Control_t
128
* \see DCMF_RecvControl
130
void ARMCIX_DCMF_ReceiveRMWResponse (void * clientdata,
131
const DCMF_Control_t * info,
134
ARMCIX_DCMF_RMWResponse_t * response = (ARMCIX_DCMF_RMWResponse_t *) info;
136
//fprintf (stderr, "ARMCIX_DCMF_ReceiveRMWResponse() - response->op == %d, response->ploc == %p, response->ival == %d, response->lval == %d, response->active == %p\n", response->op, response->ploc, response->ival, response->lval, response->active);
138
switch (response->op)
140
case ARMCI_FETCH_AND_ADD:
142
*((int *) response->ploc) = response->ival;
144
case ARMCI_FETCH_AND_ADD_LONG:
145
case ARMCI_SWAP_LONG:
146
*((long *) response->ploc) = response->lval;
149
armci_die("rmw: operation not supported",response->op);
153
// Complete the rmw operation
154
*(response->active) = 0;
159
* \brief Register the DCMF ARMCI Extention rmw operation.
161
* \see DCMF_Control_register
162
* \see DCMF_Send_register
164
void ARMCIX_DCMF_Rmw_register ()
166
DCMF_CriticalSection_enter (0);
168
DCMF_Send_Configuration_t request_configuration = {
169
DCMF_DEFAULT_SEND_PROTOCOL,
171
ARMCIX_DCMF_RecvRMWRequest,
176
DCMF_Send_register (&__rmw_request_protocol, &request_configuration);
178
DCMF_Control_Configuration_t response_configuration = {
179
DCMF_DEFAULT_CONTROL_PROTOCOL,
181
ARMCIX_DCMF_ReceiveRMWResponse,
184
DCMF_Control_register (&__rmw_response_protocol, &response_configuration);
186
DCMF_CriticalSection_exit (0);
191
* \brief ARMCI Extension blocking read-modify-write operation.
201
int ARMCIX_Rmw (int op, int * ploc, int * prem, int extra, int proc)
203
DCMF_CriticalSection_enter (0);
205
volatile unsigned active = 1;
207
//fprintf (stderr, "ARMCIX_Rmw() - op == %d, ploc == %p, prem == %p, extra == %d, proc == %d\n", op, ploc, prem, extra, proc);
209
/* Initialize the RMW request data */
210
ARMCIX_DCMF_RMWRequest_t info;
216
case ARMCI_FETCH_AND_ADD:
217
case ARMCI_FETCH_AND_ADD_LONG:
221
case ARMCI_SWAP_LONG:
225
armci_die("rmw: operation not supported",op);
229
info.active = (unsigned *)&active;
231
DCMF_Request_t request;
232
DCMF_Callback_t cb_wait = { NULL, NULL };
234
DCMF_Send ( &__rmw_request_protocol,
237
DCMF_SEQUENTIAL_CONSISTENCY,
244
//fprintf (stderr, "ARMCIX_Rmw() > active == %d (&active == %p)\n", active, &active);
245
while (active) DCMF_Messager_advance ();
246
//fprintf (stderr, "ARMCIX_Rmw() < active == %d (&active == %p)\n", active, &active);
248
DCMF_CriticalSection_exit (0);