Research Article

Optimized Data Transfers Based on the OpenCL Event Management Mechanism

Listing 5

A code with the OpenCL extension for host-to-device communication.
()  cl_context ctx;
()  MPI_Request req;
()  cl_event evt[2];
()
()  if( rank == 0 ){
()   /* receiving data from a remote device */
()   MPI_Irecv(recvbuf, bufsz, MPI_CL_MEM, 1, 0, MPI_COMM_WORLD,&req);
()   /* creating an event object of MPI_Irecv */
()   evt[0] = clCreateEventFromMPIRequest(ctx,&req,NULL);
()  /* executing a kernel during the data transfer */
()  clEnqueueNDRangeKernel(, &evt[1]);
()
()  /* executing this after the computation and communication */
()  clEnqueueWriteBuffer(cmd, buf, , 2, evt, NULL);
() }
() else if(rank ==  1){
()  /* send data to a remote host */
()  clEnqueueSendBuffer(cmd, buf, CL_TRUE, 0, bufsz, 0,);
() }