예제 #1
0
    def pyReduction_py3(msgs, msgSizes, nMsgs, returnBuffer):
        try:
            if charm.opts.PROFILING: t0 = time.time()
            contribs = []
            currentReducer = None
            for i in range(nMsgs):
                msgSize = msgSizes[i]
                if charm.opts.PROFILING: charm.msg_recv_sizes.append(msgSize)
                if msgSize > 0:
                    header, args = cPickle.loads(ffi.buffer(msgs[i], msgSize))
                    customReducer = header[b"custom_reducer"]
                    if currentReducer is None: currentReducer = customReducer
                    # check for correctness of msg
                    assert customReducer == currentReducer
                    contribs.append(args[0])

            reductionResult = getattr(charm.reducers, currentReducer)(contribs)
            rednMsg = ({b"custom_reducer": currentReducer}, [reductionResult])
            CharmLib.tempData = cPickle.dumps(rednMsg,
                                              charm.opts.PICKLE_PROTOCOL)
            returnBuffer[0] = ffi.from_buffer(CharmLib.tempData)

            if charm.opts.PROFILING:
                global times
                times[1] += (time.time() - t0)

            return len(CharmLib.tempData)
        except:
            charm.handleGeneralError()
예제 #2
0
 def recvGroupMsg_py3(gid, ep, msgSize, msg, dcopy_start):
     try:
         t0 = None
         if charm.opts.PROFILING:
             t0 = time.time()
             charm.msg_recv_sizes.append(msgSize)
         charm.recvGroupMsg(gid, ep, ffi.buffer(msg, msgSize), t0,
                            dcopy_start)
     except:
         charm.handleGeneralError()
예제 #3
0
 def recvChareMsg_py3(onPe, objPtr, ep, msgSize, msg, dcopy_start):
     try:
         t0 = None
         if charm.opts.PROFILING:
             t0 = time.time()
             charm.msg_recv_sizes.append(msgSize)
         objPtr = int(ffi.cast("uintptr_t", objPtr))
         charm.recvChareMsg((onPe, objPtr), ep, ffi.buffer(msg, msgSize),
                            t0, dcopy_start)
     except:
         charm.handleGeneralError()
예제 #4
0
 def recvArrayMsg_py3(aid, ndims, arrayIndex, ep, msgSize, msg,
                      dcopy_start):
     try:
         t0 = None
         if charm.opts.PROFILING:
             t0 = time.time()
             charm.msg_recv_sizes.append(msgSize)
         arrIndex = tuple(ffi.cast(index_ctype[ndims], arrayIndex))
         charm.recvArrayMsg(aid, arrIndex, ep, ffi.buffer(msg, msgSize), t0,
                            dcopy_start)
     except:
         charm.handleGeneralError()
예제 #5
0
    def cpickleData_py2(data, dataSize, reducerType, returnBuffers,
                        returnBufferSizes):
        try:
            if charm.opts.PROFILING: t0 = time.time()
            header = {}
            if reducerType != ReducerType.nop:
                ctype = charm.redMgr.charm_reducer_to_ctype[reducerType]
                dataTypeTuple = c_type_table[ctype]
                numElems = dataSize // dataTypeTuple[3]
                if numElems == 1:
                    pyData = [ffi.cast(dataTypeTuple[2], data)[0]]
                else:
                    if haveNumpy:
                        dt = charm.redMgr.rev_np_array_type_map[ctype]
                        a = numpy.fromstring(ffi.buffer(data, dataSize)[:],
                                             dtype=numpy.dtype(dt))
                    else:
                        array_typecode = charm.redMgr.rev_array_type_map[ctype]
                        a = array.array(array_typecode,
                                        ffi.buffer(data, dataSize)[:])
                    pyData = [a]
            else:
                pyData = []

            msg = (header, pyData)
            # save msg, else it might be deleted before returning control to libcharm
            CharmLib.tempData = cPickle.dumps(msg, charm.opts.PICKLE_PROTOCOL)
            returnBuffers[0] = ffi.from_buffer(CharmLib.tempData)
            returnBufferSizes[0] = len(CharmLib.tempData)

            if charm.opts.PROFILING:
                global times
                times[0] += (time.time() - t0)

        except:
            charm.handleGeneralError()
예제 #6
0
 def arrayElemJoin_py3(aid, ndims, arrayIndex, ep, msg, msgSize):
     try:
         t0 = None
         if charm.opts.PROFILING:
             t0 = time.time()
             charm.msg_recv_sizes.append(msgSize)
         arrIndex = tuple(ffi.cast(index_ctype[ndims], arrayIndex))
         charm.recvArrayMsg(aid,
                            arrIndex,
                            ep,
                            ffi.buffer(msg, msgSize),
                            t0,
                            -1,
                            migration=True)
     except:
         charm.handleGeneralError()
예제 #7
0
 def recvReadOnly_py3(msgSize, msg):
     try:
         charm.recvReadOnly(ffi.buffer(msg, msgSize))
     except:
         charm.handleGeneralError()