User`s guide

Developing LUC Applications [5]
// Reduction service.
// This routine is called by the LUC server library
// when a client request of type
// (svc_type,reduce_func_idx) is received.
luc_error_t reduce(void *inPtr, u_int64_t inDataLen,
void **outPtr, u_int64_t *outDataLen,
void **completionArg, LUC_Mem_Avail_Completion *completionFctn,
luc_endpoint_id_t callerEndpoint)
{
double *input = (double *) inPtr; // input data
double *output = NULL;
int n = inDataLen / sizeof(double); // number of values to sum
// Default (error) return will be no output data
*outPtr = NULL;
*completionArg = NULL;
*completionFctn = NULL;
// Allocate space for the return data
output = (double *)malloc(sizeof(double));
if (NULL == output)
{
return LUC_ERR_RESOURCE_FAILURE; // or use a custom code
}
NetworkToHost(input,inDataLen); // convert data to host byte order
// Perform the reduction.
double sum = 0;
for (int i=0;i < n;i++) sum += input[i];
*output = sum; // set result value
HostToNetwork(output,sizeof(double)); // convert result to network byte order
*outDataLen = sizeof(double); // set result size
*outPtr = (void *)output; // set result / output pointer
// Tell LUC to call 'free' when it is done without the output data.
// Pass the 'output' pointer to free()
*completionArg = output;
*completionFctn = free;
return LUC_ERR_OK;
}
// The LUC server can run on the XMT login node or in the compute partition.
// Return value is 0 for success, 1 for error.
int server(int threadCount)
{
luc_error_t err; // result code from LUC calls
// Create the LUC server endpoint.
LucEndpoint *svrEndpoint = luc_allocate_endpoint(LUC_SERVER_ONLY);
// Register routines which implement the services.
S247920 63