void test_chunk_setup(cl_context context, cl_command_queue queue, size_t size, size_t offset, int isGPU) { if(size == 0) return; cl_mem* d_a = isGPU ? &dg_a : &dc_a; cl_mem* d_b = isGPU ? &dg_b : &dc_b; cl_mem_flags a_flags = CL_MEM_READ_WRITE; cl_mem_flags b_flags = CL_MEM_READ_WRITE; void* a_mem = NULL; void* b_mem = NULL; if(!isGPU) { a_flags |= CL_MEM_USE_HOST_PTR; a_mem = h_a; } int err; *d_a = clCreateBuffer(context, a_flags, sizeof(*h_a) * size, a_mem, &err); CHKERR(err, "Failed to create chunk buffers!"); *d_b = clCreateBuffer(context, b_flags, sizeof(*h_b) * size, b_mem, &err); CHKERR(err, "Failed to create chunk buffers!"); err = clEnqueueWriteBuffer(queue, *d_a, CL_FALSE, 0, sizeof(*h_a) * size, h_a + offset, 0, NULL, NULL); CHKERR(err, "Failed to write chunk buffer A!"); }
ErrorCode ReadCCMIO::get_str_option(const char *opt_str, EntityHandle seth, Tag &tag, CCMIOID node, const char *other_tag_name) { int len; CCMIOError error = kCCMIONoErr; std::vector<char> opt_string; if (kCCMIONoErr != CCMIOReadOptstr(NULL, node, opt_str, &len, NULL)) return MB_SUCCESS; opt_string.resize(len); CCMIOReadOptstr(&error, node, opt_str, &len, &opt_string[0]); ErrorCode rval = MB_SUCCESS; if (!tag) { rval = mbImpl->tag_get_handle( other_tag_name ? other_tag_name : opt_str, NAME_TAG_SIZE, MB_TYPE_OPAQUE, tag, MB_TAG_SPARSE|MB_TAG_CREAT ); CHKERR(rval, NULL); } if (opt_string.size() > NAME_TAG_SIZE) opt_string[NAME_TAG_SIZE-1] = '\0'; else (opt_string.resize(NAME_TAG_SIZE, '\0')); rval = mbImpl->tag_set_data(tag, &seth, 1, &opt_string[0]); CHKERR(rval, NULL); return MB_SUCCESS; }
cl_kernel create_kernel(const char* filename, const char* kernel, const cl_context context, const cl_device_id device) { cl_kernel kernel_compute; // Create a command queue cl_program program = createProgramFromSource(filename, context); // Build the program executable //int err = clBuildProgram(program, 1, &device, "-cl-opt-disable", NULL, NULL); int err = clBuildProgram(program, 1, &device, NULL, NULL, NULL); if (err == CL_BUILD_PROGRAM_FAILURE) { char *log; size_t logLen; err = clGetProgramBuildInfo(program, device_id_gpu, CL_PROGRAM_BUILD_LOG, 0, NULL, &logLen); log = (char *) malloc(sizeof(char)*logLen); err = clGetProgramBuildInfo(program, device_id_gpu, CL_PROGRAM_BUILD_LOG, logLen, (void *) log, NULL); fprintf(stdout, "CL Error %d: Failed to build program! Log:\n%s", err, log); free(log); exit(1); } CHKERR(err, "Failed to build program!"); // Create the compute kernel in the program we wish to run kernel_compute = clCreateKernel(program, kernel, &err); CHKERR(err, "Failed to create a compute kernel!"); return kernel_compute; }
void Meta_SDcard_OP(SDCARD_REQ *req, char *peer_buf, unsigned short peer_len) { SDCARD_CNF cnf; int bufsz = 512; char fname[512]; char buf[512]; unsigned char cid[16]; unsigned char csd[16]; memset(&cnf, 0, sizeof(SDCARD_CNF)); cnf.header.id = FT_SDCARD_CNF_ID; cnf.header.token = req->header.token; cnf.status = META_SUCCESS; sprintf(fname, "%s/cid", path); CHKERR(meta_sdcard_read_info(fname, buf, bufsz)); memcpy(cid,buf,16*sizeof(unsigned char)); sprintf(fname, "%s/csd", path); CHKERR(meta_sdcard_read_info(fname, buf, bufsz)); memcpy(csd,buf,16*sizeof(unsigned char)); meta_sdcard_send_resp(&cnf); return; error: cnf.status = META_FAILED; meta_sdcard_send_resp(&cnf); return; }
int Sm_list_clear(const char *fileName, int lineNbr, PsmPartition partition, PsmAddress list, SmListDeleteFn deleteFn, void *arg) { CHKERR(partition); CHKERR(list); return wipeList(fileName, lineNbr, partition, list, deleteFn, arg, 0); }
herr_t op_func_group (hid_t loc_id, const char* objname, const H5L_info_t* /*info*/, void* /*ppar*/) { //struct param glopar; struct param* ppar; ppar = &glopar; int err; hid_t h5fi; hid_t h5fo; hid_t gid; H5G_stat_t statbuf; err = H5Gget_objinfo (loc_id, objname, 0, &statbuf); CHKERR(err); /* if object is group, open containers, create group, iterate over datasets, close */ if (statbuf.type == H5G_GROUP) { h5fi = H5Fopen(((struct param *)ppar)->conti, H5F_ACC_RDONLY, H5P_DEFAULT); CHKRTN(h5fi < 0, FILEERR); h5fo = H5Fopen(((struct param *)ppar)->conto, H5F_ACC_RDWR, H5P_DEFAULT); CHKRTN(h5fo < 0, FILEERR); gid = H5Gcreate(h5fo, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHKRTN(gid < 0, ERR); strncpy(((struct param *)ppar)->grupi, objname, sizeof(((struct param *)ppar)->grupi) - 1); strncpy(((struct param *)ppar)->grupo, objname, sizeof(((struct param *)ppar)->grupo) - 1); err = H5Literate_by_name (h5fi, objname, H5_INDEX_NAME, H5_ITER_NATIVE, NULL, op_func_dset, (void *) ppar, NULL); CHKERR(err); err = H5Fclose(h5fo); CHKERR(err); err = H5Fclose(h5fi); CHKERR(err); } return EXIT_SUCCESS; }
void test_chunk_kernel(cl_context context, cl_command_queue queue, cl_device_id device, cl_kernel kernel, size_t size, size_t offset, int isGPU) { if(size == 0) return; cl_mem* d_a = isGPU ? &dg_a : &dc_a; cl_mem* d_b = isGPU ? &dg_b : &dc_b; size_t chunk = isGPU ? 2 : size; cl_event* event = isGPU ? &event_gpu : &event_cpu; size_t local_size; clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &local_size, NULL); if(!isGPU) local_size = 1; int err = clSetKernelArg(kernel, 0, sizeof(cl_mem), d_a); err |= clSetKernelArg(kernel, 1, sizeof(cl_mem), d_b); err |= clSetKernelArg(kernel, 2, sizeof(size_t), &size); err |= clSetKernelArg(kernel, 3, sizeof(size_t), &chunk); if(isGPU) err |= clSetKernelArg(kernel, 4, sizeof(reduce_t) * local_size * 2, NULL); CHKERR(err, "Errors setting kernel arguments"); size_t groups = size / local_size / chunk + (size % (local_size*chunk) == 0 ? 0 : 1); size_t global_size = groups * local_size; err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global_size, &local_size, 0, NULL, event); CHKERR(err, "Failed to run kernel!"); if(groups != 1) { cl_mem temp = *d_a; *d_a = *d_b; *d_b = temp; test_chunk_kernel(context, queue, device, kernel, groups, offset, isGPU); } }
cl_program ocdBuildProgramFromFile(cl_context context,cl_device_id device_id,const char* kernel_file_name) { cl_int err; cl_program program; size_t kernelLength; char* kernelSource; FILE* kernel_fp; size_t items_read; #ifdef USE_AFPGA const char* kernel_file_mode = "rb"; #else //CPU or GPU const char* kernel_file_mode = "r"; #endif kernel_fp = fopen(kernel_file_name, kernel_file_mode); check(kernel_fp != NULL,"common_ocl.ocdBuildProgramFromFile() - Cannot open kernel file!"); fseek(kernel_fp, 0, SEEK_END); kernelLength = (size_t) ftell(kernel_fp); kernelSource = malloc(sizeof(char)*kernelLength); check(kernelSource != NULL,"common_ocl.ocdBuildProgramFromFile() - Heap Overflow! Cannot allocate space for kernelSource."); rewind(kernel_fp); items_read = fread((void *) kernelSource, kernelLength, 1, kernel_fp); check(items_read == 1,"common_ocl.ocdBuildProgramFromFile() - Error reading from kernelFile"); fclose(kernel_fp); /* Create the compute program from the source buffer */ #ifdef USE_AFPGA //use Altera FPGA program = clCreateProgramWithBinary(context,1,&device_id,&kernelLength,(const unsigned char**)&kernelSource,NULL,&err); #else //CPU or GPU program = clCreateProgramWithSource(context, 1, (const char **) &kernelSource, &kernelLength, &err); #endif CHKERR(err, "common_ocl.ocdBuildProgramFromFile() - Failed to create a compute program!"); /* Build the program executable */ #ifdef USE_AFPGA //use Altera FPGA err = clBuildProgram(program,1,&device_id,"-DOPENCL -I.",NULL,NULL); #else err = clBuildProgram(program, 0, NULL, "-DOPENCL -I.", NULL, NULL); #endif if (err == CL_BUILD_PROGRAM_FAILURE) { char *buildLog; size_t logLen; err = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &logLen); buildLog = (char *) malloc(sizeof(char)*logLen); check(buildLog != NULL,"common_ocl.ocdBuildProgramFromFile() - Heap Overflow! Cannot allocate space for buildLog."); err = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, logLen, (void *) buildLog, NULL); fprintf(stderr, "CL Error %d: Failed to build program! Log:\n%s", err, buildLog); free(buildLog); exit(1); } CHKERR(err,"common_ocl.ocdBuildProgramFromFile() - Failed to build program!"); free(kernelSource); /* Free kernel source */ return program; }
TEMPLATE_PLEASE int map_vecs_Sprimme(HSCALAR *V, int m, int nV, int ldV, HSCALAR *W, int n0, int n, int ldW, int *p, primme_context ctx) { int i; /* Loop variable */ /* Compute the norm of the columns V(n0:n-1) */ HREAL *Vnorms = NULL; CHKERR(Num_malloc_RHprimme(nV, &Vnorms, ctx)); for (i = 0; i < nV; i++) { Vnorms[i] = sqrt(REAL_PART( Num_dot_SHprimme(m, &V[ldV * i], 1, &V[ldV * i], 1, ctx))); } /* Compute V'*W[n0:n-1] */ HSCALAR *ip = NULL; CHKERR(Num_malloc_SHprimme(nV * (n - n0), &ip, ctx)); Num_zero_matrix_SHprimme(ip, nV, n - n0, nV, ctx); CHKERR(Num_gemm_SHprimme("C", "N", nV, n - n0, m, 1.0, V, ldV, &W[ldW * n0], ldW, 0.0, ip, nV, ctx)); for (i = n0; i < n; i++) { /* Find the j that maximizes ABS(V[j]'*W[i]/Vnorms[j]) and is not */ /* in p(0:i-1) */ int j, jmax=-1; HREAL ipmax = -1; for (j = 0; j < nV; j++) { HREAL ipij = ABS(ip[nV * (i - n0) + j]); if (ipij > ipmax * Vnorms[j]) { /* Check that j is not in p(0:i-1) */ int k; for (k = 0; k < i && p[k] != j; k++) ; if (k < i) continue; /* Update ipmax and jmax */ ipmax = fabs(ipij / Vnorms[j]); jmax = j; } } if (jmax < 0) { jmax = i; } /* Assign the map */ p[i] = jmax; } CHKERR(Num_free_RHprimme(Vnorms, ctx)); CHKERR(Num_free_SHprimme(ip, ctx)); return 0; }
PsmAddress sm_list_prev(PsmPartition partition, PsmAddress elt) { SmListElt *eltBuffer; CHKERR(partition); CHKERR(elt); eltBuffer = (SmListElt *) psp(partition, elt); CHKERR(eltBuffer); return eltBuffer->prev; }
int ltpei_parse_extension(char **cursor, int *bytesRemaining, Lyst exts, unsigned int *extensionOffset) { char *initialCursor; LtpExtensionInbound *extField; unsigned int valueLength; CHKERR(cursor); CHKERR(*cursor); CHKERR(bytesRemaining); CHKERR(exts); if ((*bytesRemaining) < 1) { return 0; /* Corrupt. */ } extField = MTAKE(sizeof(LtpExtensionInbound)); if (extField == NULL) { return -1; /* Give up. */ } initialCursor = *cursor; extField->offset = *extensionOffset; extField->tag = **cursor; (*cursor)++; (*bytesRemaining)--; extractSmallSdnv(&valueLength, cursor, bytesRemaining); if (valueLength == 0 || *bytesRemaining < valueLength) { return 0; /* Corrupt. */ } extField->length = valueLength; extField->value = MTAKE(valueLength); if (extField->value == 0) { MRELEASE(extField); return -1; /* Give up. */ } memcpy(extField->value, *cursor, valueLength); (*cursor) += valueLength; (*bytesRemaining) -= valueLength; if (lyst_insert_last(exts, extField) == NULL) { MRELEASE(extField->value); MRELEASE(extField); return -1; /* Give up. */ } *extensionOffset += ((*cursor) - initialCursor); return 1; }
int dtn2_updateRule(char *nodeNm, char *demux, FwdDirective *directive) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object elt; OBJ_POINTER(Dtn2Plan, plan); Object ruleAddr; Dtn2Rule ruleBuf; CHKERR(nodeNm && demux && directive); if (*demux == '\0') { writeMemo("[?] Zero-length DTN2 rule demux."); return 0; } if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); elt = locatePlan(nodeName, NULL); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] No plan defined for this node", nodeNm); return 0; } GET_OBJ_POINTER(sdr, Dtn2Plan, plan, sdr_list_data(sdr, elt)); dtn2_findRule(nodeName, demux, plan, &ruleAddr, &elt); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Unknown rule", demux); return 0; } /* All parameters validated, okay to update the rule. */ sdr_stage(sdr, (char *) &ruleBuf, ruleAddr, sizeof(Dtn2Rule)); dtn2_destroyDirective(&ruleBuf.directive); memcpy((char *) &ruleBuf.directive, (char *) directive, sizeof(FwdDirective)); sdr_write(sdr, ruleAddr, (char *) &ruleBuf, sizeof(Dtn2Rule)); if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't update rule.", NULL); return -1; } return 1; }
ErrorCode ReadCCMIO::read_all_faces(CCMIOID topologyID, TupleList &vert_map, TupleList &face_map #ifndef TUPLE_LIST ,SenseList &sense_map #endif , Range *new_faces) { CCMIOSize_t index = CCMIOSIZEC(0); CCMIOID faceID; ErrorCode rval; // get total # internal/bdy faces, size the face map accordingly int nint_faces = 0, nbdy_faces = 0; CCMIOSize_t nf; CCMIOError error = kCCMIONoErr; while (kCCMIONoErr == CCMIONextEntity(NULL, topologyID, kCCMIOBoundaryFaces, &index, &faceID)) { CCMIOEntitySize(&error, faceID, &nf, NULL); nbdy_faces = nbdy_faces + nf; } CCMIOGetEntity(&error, topologyID, kCCMIOInternalFaces, 0, &faceID); CCMIOEntitySize(&error, faceID, &nf, NULL); nint_faces = nint_faces + nf; #ifdef TUPLE_LIST face_map.resize(2*nint_faces + nbdy_faces); #endif // get multiple blocks of bdy faces index = CCMIOSIZEC(0); while (kCCMIONoErr == CCMIONextEntity(NULL, topologyID, kCCMIOBoundaryFaces, &index, &faceID)) { rval = read_faces(faceID, kCCMIOBoundaryFaces, vert_map, face_map #ifndef TUPLE_LIST , sense_map #endif , new_faces); CHKERR(rval, "Trouble reading boundary faces."); } // now get internal faces CCMIOGetEntity(&error, topologyID, kCCMIOInternalFaces, 0, &faceID); rval = read_faces(faceID, kCCMIOInternalFaces, vert_map,face_map #ifndef TUPLE_LIST , sense_map #endif , new_faces); CHKERR(rval, "Trouble reading internal faces."); return rval; }
int dtn2_removeRule(char *nodeNm, char *demux) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object elt; OBJ_POINTER(Dtn2Plan, plan); Object ruleAddr; OBJ_POINTER(Dtn2Rule, rule); CHKERR(nodeNm && demux); if (*demux == '\0') { writeMemo("[?] Zero-length DTN2 rule demux."); return 0; } if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); elt = locatePlan(nodeName, NULL); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] No plan defined for this node", nodeNm); return 0; } GET_OBJ_POINTER(sdr, Dtn2Plan, plan, sdr_list_data(sdr, elt)); dtn2_findRule(nodeName, demux, plan, &ruleAddr, &elt); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Unknown rule", demux); return 0; } /* All parameters validated, okay to remove the rule. */ GET_OBJ_POINTER(sdr, Dtn2Rule, rule, ruleAddr); dtn2_destroyDirective(&(rule->directive)); sdr_free(sdr, ruleAddr); sdr_list_delete(sdr, elt, NULL, NULL); if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't remove rule.", NULL); return -1; } return 1; }
int ltpei_add_xmit_trailer_extension(LtpXmitSeg *segment, char tag, int valueLength, char *value) { Sdr sdr = getIonsdr(); Sdnv sdnv; LtpExtensionOutbound extension; Object addr; CHKERR(segment); CHKERR(ionLocked()); encodeSdnv(&sdnv, valueLength); if (segment->pdu.trailerExtensions == 0) { if ((segment->pdu.trailerExtensions = sdr_list_create(sdr)) == 0) { return -1; /* No space in SDR heap. */ } } extension.tag = tag; extension.length = valueLength; if (valueLength == 0) { extension.value = 0; } else { CHKERR(value); extension.value = sdr_insert(sdr, value, valueLength); if (extension.value == 0) { return -1; /* No space in SDR heap. */ } } if ((addr = sdr_insert(sdr, (char *) &extension, sizeof(LtpExtensionOutbound))) == 0) { return -1; /* No space in SDR heap. */ } if (sdr_list_insert_last(sdr, segment->pdu.trailerExtensions, addr) == 0) { return -1; /* No space in SDR heap. */ } segment->pdu.trailerExtensionsCount++; segment->pdu.trailerLength += (1 + sdnv.length + valueLength); return 0; }
int dtn2_addPlan(char *nodeNm, FwdDirective *defaultDir) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object nextPlan; Dtn2Plan plan; Object planObj; CHKERR(nodeNm && defaultDir); if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); if (locatePlan(nodeName, &nextPlan) != 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Duplicate plan", nodeNm); return 0; } /* Okay to add this plan to the database. */ plan.nodeName = sdr_string_create(sdr, nodeName); memcpy((char *) &plan.defaultDirective, (char *) defaultDir, sizeof(FwdDirective)); plan.rules = sdr_list_create(sdr); planObj = sdr_malloc(sdr, sizeof(Dtn2Plan)); if (planObj) { if (nextPlan) { oK(sdr_list_insert_before(sdr, nextPlan, planObj)); } else { oK(sdr_list_insert_last(sdr, (_dtn2Constants())->plans, planObj)); } sdr_write(sdr, planObj, (char *) &plan, sizeof(Dtn2Plan)); } if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't add plan.", nodeNm); return -1; } return 1; }
long sdr_list_length(Sdr sdrv, Object list) { SdrState *sdr; SdrList listBuffer; CHKERR(sdrv); CHKERR(list); sdr = sdrv->sdr; CHKERR(takeSdr(sdr) == 0); sdrFetch(listBuffer, list); releaseSdr(sdr); return listBuffer.length; }
ErrorCode ReadCCMIO::read_gids_and_types(CCMIOID /* problemID */, CCMIOID topologyID, std::vector<EntityHandle> &cells) { // get the cells entity and number of cells CCMIOSize_t dum_cells; int num_cells; CCMIOError error = kCCMIONoErr; CCMIOID cellsID, mapID; CCMIOGetEntity(&error, topologyID, kCCMIOCells, 0, &cellsID); CCMIOEntitySize(&error, cellsID, &dum_cells, NULL); num_cells = GETINT32(dum_cells); // check the number of cells against how many are in the cell array if (num_cells != (int)cells.size()) CHKERR(MB_FAILURE, "Number of cells doesn't agree."); // read the gid map and set global ids std::vector<int> cell_gids(num_cells); CCMIOReadCells(&error, cellsID, &mapID, NULL, CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd)); CCMIOReadMap(&error, mapID, &cell_gids[0], CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd)); CHKCCMERR(error, "Couldn't read cells or cell id map."); ErrorCode rval = mbImpl->tag_set_data(mGlobalIdTag, &cells[0], cells.size(), &cell_gids[0]); CHKERR(rval, "Couldn't set gids tag."); // now read cell material types; reuse cell_gids CCMIOReadCells(&error, cellsID, NULL, &cell_gids[0], CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd)); CHKCCMERR(error, "Trouble reading cell types."); // create the matsets std::map<int, Range> matset_ents; for (int i = 0; i < num_cells; i++) matset_ents[cell_gids[i]].insert(cells[i]); for (std::map<int, Range>::iterator mit = matset_ents.begin(); mit != matset_ents.end(); mit++) { EntityHandle matset; rval = mbImpl->create_meshset(MESHSET_SET, matset); CHKERR(rval, "Couldn't create material set."); newMatsets[mit->first] = matset; rval = mbImpl->add_entities(matset, mit->second); CHKERR(rval, "Couldn't add entities to material set."); } return MB_SUCCESS; }
ErrorCode ReadCCMIO::read_cells(CCMIOSize_t /* proc */, CCMIOID problemID, CCMIOID /* verticesID */, CCMIOID topologyID, TupleList &vert_map, Range *new_ents) { // read the faces. // face_map fields: s:forward/reverse, i: cell id, ul: face handle, r: none ErrorCode rval; #ifdef TUPLE_LIST TupleList face_map(1, 1, 1, 0, 0); #else TupleList face_map; SenseList sense_map; #endif rval = read_all_faces(topologyID, vert_map, face_map #ifndef TUPLE_LIST , sense_map #endif , new_ents); CHKERR(rval, NULL); // read the cell topology types, if any exist in the file std::map<int,int> cell_topo_types; rval = read_topology_types(topologyID, cell_topo_types); CHKERR(rval, "Problem reading cell topo types."); // now construct the cells; sort the face map by cell ids first #ifdef TUPLE_LIST rval = face_map.sort(1); CHKERR(rval, "Couldn't sort face map by cell id."); #endif std::vector<EntityHandle> new_cells; rval = construct_cells(face_map, #ifndef TUPLE_LIST sense_map, #endif vert_map, cell_topo_types, new_cells); CHKERR(rval, NULL); if (new_ents) { Range::iterator rit = new_ents->end(); std::vector<EntityHandle>::reverse_iterator vit; for (vit = new_cells.rbegin(); vit != new_cells.rend(); vit++) rit = new_ents->insert(rit, *vit); } rval = read_gids_and_types(problemID, topologyID, new_cells); CHKERR(rval, NULL); return MB_SUCCESS; }
static int reforwardStrandedBundles() { Sdr sdr = getIonsdr(); BpDB *bpConstants = getBpConstants(); Object elt; Object nextElt; CHKERR(sdr_begin_xn(sdr)); for (elt = sdr_list_first(sdr, bpConstants->limboQueue); elt; elt = nextElt) { nextElt = sdr_list_next(sdr, elt); if (releaseFromLimbo(elt, 0) < 0) { putErrmsg("Failed releasing bundle from limbo.", NULL); sdr_cancel_xn(sdr); return -1; } } if (sdr_end_xn(sdr) < 0) { putErrmsg("brss failed limbo release on client connect.", NULL); return -1; } return 0; }
cl_program createProgramFromSource(const char* filename, const cl_context context) { FILE* kernelFile = NULL; kernelFile = fopen(filename, "r"); if(!kernelFile) fprintf(stdout,"Error reading file.\n"), exit(0); fseek(kernelFile, 0, SEEK_END); size_t kernelLength = (size_t) ftell(kernelFile); char* kernelSource = (char *) calloc(1, sizeof(char)*kernelLength+1); rewind(kernelFile); if(fread((void *) kernelSource, kernelLength, 1, kernelFile) == 0) { fprintf(stderr, "Could not read source\n"); exit(1); } kernelSource[kernelLength] = 0; fclose(kernelFile); // Create the compute program from the source buffer int err; program = clCreateProgramWithSource(context, 1, (const char **) &kernelSource, NULL, &err); CHKERR(err, "Failed to create a compute program!"); free(kernelSource); return program; }
int psm_set_root(PsmPartition partition, PsmAddress root) { PartitionMap *map; int err = 0; CHKERR(partition); map = (PartitionMap *) (partition->space); lockPartition(map); if (map->directory != 0) { putErrmsg("Partition already has root value; erase it first.", NULL); err = -1; } else { if (root == 0) { writeMemo("[i] New partition root value is zero."); } map->directory = root; } unlockPartition(map); return err; }
cl_mem alloc(cl_context context, int N) { int err; cl_mem mem = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(T)*N, NULL, &err); CHKERR(err, "Unable to allocate memory"); return mem; }
double LisMPIDiscreteVector::getNormInf() { double val = .0; int err = lis_vector_nrmi(_v, &val); CHKERR(err); return val; }
int acsAttach() { if (acsConstants) { return 0; } if (getAcssdr() == NULL) { /* ACS can't find ACS SDR. */ return -1; } CHKERR(sdr_begin_xn(acsSdr)); if (acsdbObject == 0) { acsdbObject = sdr_find(acsSdr, acsDbName, NULL); if (acsdbObject == 0) { sdr_exit_xn(acsSdr); return -1; } } acsConstants = &acsConstantsBuf; sdr_read(acsSdr, (char *) acsConstants, acsdbObject, sizeof(AcsDB)); sdr_exit_xn(acsSdr); return 0; }
int dtn2_removePlan(char *nodeNm) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object elt; Object planObj; OBJ_POINTER(Dtn2Plan, plan); CHKERR(nodeNm); if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); elt = locatePlan(nodeName, NULL); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Unknown plan", nodeNm); return 0; } planObj = sdr_list_data(sdr, elt); GET_OBJ_POINTER(sdr, Dtn2Plan, plan, planObj); if (sdr_list_length(sdr, plan->rules) > 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Can't remove plan; still has rules", nodeNm); return 0; } /* Okay to remove this plan from the database. */ sdr_list_delete(sdr, elt, NULL, NULL); dtn2_destroyDirective(&(plan->defaultDirective)); sdr_list_destroy(sdr, plan->rules, NULL, NULL); sdr_free(sdr, plan->nodeName); sdr_free(sdr, planObj); if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't remove plan.", nodeNm); return -1; } return 1; }
void download(cl_command_queue commands, T* dst, cl_mem src, int N) { int err = clEnqueueReadBuffer(commands, src, CL_TRUE, 0, sizeof(T)*N, dst, 0, NULL, &ocdTempEvent); clFinish(commands); START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "CFD Data Copy", ocdTempTimer) END_TIMER(ocdTempTimer) CHKERR(err, "Unable to read memory from device"); }
void upload(cl_command_queue commands, cl_mem dst, T* src, int N) { int err = clEnqueueWriteBuffer(commands, dst, CL_TRUE, 0, sizeof(T) * N, src, 0, NULL, &ocdTempEvent); clFinish(commands); START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "CFD Data Copy", ocdTempTimer) END_TIMER(ocdTempTimer) CHKERR(err, "Unable to write memory to device"); }
void initGpu() { int err; ///////////////////////////////////////////////////////////// // Basic OpenCL Setup device_id = GetDevice(platform_id, n_device); // Create a compute context context = clCreateContext(0, 1, &device_id, NULL, NULL, &err); CHKERR(err, "Failed to create a compute context!"); // Create a command queue commands = clCreateCommandQueue(context, device_id, CL_QUEUE_PROFILING_ENABLE, &err); CHKERR(err, "Failed to create a command queue!"); ///////////////////////////////////////////////////////////// }
long sdr_list_length(Sdr sdrv, Object list) { SdrList listBuffer; CHKERR(list); sdrFetch(listBuffer, list); return listBuffer.length; }