GtIntset *gt_intset_16_io_fp(GtIntset *intset, FILE *fp, GtError *err, GtIOFunc io_func) { int had_err = 0; GtUword type = (GtUword) GT_INTSET_16_TYPE; GtIntset16 *intset_16; GtIntsetMembers *members; gt_error_check(err); intset_16 = gt_intset_16_cast(intset); had_err = gt_intset_16_io_one(type); if (!had_err && type != GT_INTSET_16_TYPE) { /* only applies to reading */ had_err = 1; gt_error_set(err, "Trying to read GtIntset16 from file," " type does not match!"); } if (!had_err) { members = intset->members; had_err = gt_intset_16_io_one(members->currentsectionnum); if (!had_err) had_err = gt_intset_16_io_one(members->maxelement); if (!had_err) had_err = gt_intset_16_io_one(members->nextfree); if (!had_err) had_err = gt_intset_16_io_one(members->num_of_elems); if (!had_err) had_err = gt_intset_16_io_one(members->previouselem); if (!had_err) { members->logsectionsize = GT_BITS_FOR_TYPE(uint16_t); members->numofsections = GT_ELEM2SECTION_M(members->maxelement) + 1; members->sectionstart = gt_realloc(members->sectionstart, sizeof (*members->sectionstart) * (members->numofsections + 1)); } had_err = io_func(members->sectionstart, sizeof (*members->sectionstart), (size_t) (members->numofsections + 1), fp, err); if (!had_err && members->sectionstart[0] != 0) { had_err = 1; gt_error_set(err, "Unexpected value in sectionstart[0]: " GT_WU " expected 0!", members->sectionstart[0]); } } if (!had_err) { intset_16->elements = gt_realloc(intset_16->elements, sizeof (*intset_16->elements) * members->num_of_elems); had_err = io_func(intset_16->elements, sizeof (*intset_16->elements), (size_t) members->num_of_elems, fp, err); } if (had_err) { gt_intset_16_delete(intset); intset = NULL; } return intset; }
static int bio_io(BIO *bio, void *buf, int len, size_t method_offset, int callback_flags, size_t *num) { int i; typedef int (*io_func_t)(BIO *, char *, int); io_func_t io_func = NULL; if (bio != NULL && bio->method != NULL) { io_func = *((const io_func_t *)(((const uint8_t *)bio->method) + method_offset)); } if (io_func == NULL) { OPENSSL_PUT_ERROR(BIO, bio_io, BIO_R_UNSUPPORTED_METHOD); return -2; } if (bio->callback != NULL) { i = (int) bio->callback(bio, callback_flags, buf, len, 0L, 1L); if (i <= 0) { return i; } } if (!bio->init) { OPENSSL_PUT_ERROR(BIO, bio_io, BIO_R_UNINITIALIZED); return -2; } i = 0; if (buf != NULL && len > 0) { i = io_func(bio, buf, len); } if (i > 0) { *num += i; } if (bio->callback != NULL) { i = (int)(bio->callback(bio, callback_flags | BIO_CB_RETURN, buf, len, 0L, (long)i)); } return i; }
// Returns error condition in *errcode, if non-zero, return value is number of bytes written // before error condition occured. If *errcode == 0, returns total bytes written (which will // be equal to input size). mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode, byte flags) { byte *buf = buf_; mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream); typedef mp_uint_t (*io_func_t)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode); io_func_t io_func; const mp_stream_p_t *stream_p = s->type->protocol; if (flags & MP_STREAM_RW_WRITE) { io_func = (io_func_t)stream_p->write; } else { io_func = stream_p->read; } *errcode = 0; mp_uint_t done = 0; while (size > 0) { mp_uint_t out_sz = io_func(stream, buf, size, errcode); // For read, out_sz == 0 means EOF. For write, it's unspecified // what it means, but we don't make any progress, so returning // is still the best option. if (out_sz == 0) { return done; } if (out_sz == MP_STREAM_ERROR) { // If we read something before getting EAGAIN, don't leak it if (mp_is_nonblocking_error(*errcode) && done != 0) { *errcode = 0; } return done; } if (flags & MP_STREAM_RW_ONCE) { return out_sz; } buf += out_sz; size -= out_sz; done += out_sz; } return done; }
int main(int argc, char** argv) { struct options options; if (process_options(argc, argv, true, &options) != 0) return 0; if (options.rmat.a + options.rmat.b + options.rmat.c >= 1) { printf("Error: The sum of probabilities must equal 1\n"); return 0; } double d = 1 - (options.rmat.a + options.rmat.b + options.rmat.c); xscale_node = options.rmat.xscale_node; xscale_interval = options.rmat.xscale_interval; uint_fast32_t seed[5]; make_mrg_seed(options.rng.userseed1, options.rng.userseed2, seed); mrg_state state; mrg_seed(&state, seed); //mrg_skip(&new_state, 50, 7, 0); // Do an initial skip? edge_t total_edges = options.rmat.edges; if((total_edges % options.rmat.xscale_interval) > options.rmat.xscale_node) { total_edges /= options.rmat.xscale_interval; total_edges++; } else { total_edges /= options.rmat.xscale_interval; } if (options.global.symmetric) { total_edges *= 2; } printf("Generator type: R-MAT\n"); printf("Scale: %d (%" PRIu64 " vertices)\n", options.rmat.scale, ((uint64_t)1 << options.rmat.scale)); printf("Edges: %" PRIet "\n", total_edges); printf("Probabilities: A=%4.2f, B=%4.2f, C=%4.2f, D=%4.2f\n", options.rmat.a, options.rmat.b, options.rmat.c, d); double start = get_time(); // io thread size_t buffer_size = calculate_buffer_size(options.global.buffer_size); buffer_queue flushq; buffer_manager manager(&flushq, options.global.buffers_per_thread, buffer_size); io_thread_func io_func(options.global.graphname.c_str(), total_edges, &flushq, &manager, buffer_size); boost::thread io_thread(boost::ref(io_func)); // worker threads int nthreads = options.global.nthreads; edge_t edges_per_thread = options.rmat.edges / nthreads; threadid_t* workers[nthreads]; boost::thread* worker_threads[nthreads]; for (int i = 0; i < nthreads; i++) { workers[i] = new threadid_t(i); thread_buffer* buffer = manager.register_thread(*workers[i]); // last thread gets the remainder (if any) edge_t start = i * edges_per_thread; edge_t end = (i == nthreads-1) ? (options.rmat.edges) : ((i+1) * edges_per_thread); worker_threads[i] = new boost::thread(generate, buffer, state, options.rmat.scale, start, end, options.rmat.a, options.rmat.b, options.rmat.c, /*d,*/ options.global.symmetric); } // Wait until work completes for (int i = 0; i < nthreads; i++) { worker_threads[i]->join(); } io_func.stop(); io_thread.join(); // cleanup for (int i = 0; i < nthreads; i++) { manager.unregister_thread(*workers[i]); delete worker_threads[i]; delete workers[i]; } double elapsed = get_time() - start; printf("Generation time: %fs\n", elapsed); make_ini_file(options.global.graphname.c_str(), (uint64_t)1 << options.rmat.scale, total_edges); return 0; }
int main_503_3() { int arg4 = 1; set_rings_addresses(); io_func((void*)&arg4); }
int main_503_2() { int arg3 = 0; set_rings_addresses(); io_func((void*)&arg3); }