void iguana_acceptloop(void *args) { struct iguana_peer *addr; struct iguana_info *coin = args; struct pollfd pfd; int32_t sock; struct iguana_accept *ptr; uint16_t port = coin->chain->portp2p; socklen_t clilen; struct sockaddr_in cli_addr; char ipaddr[64]; uint32_t i,ipbits; while ( (coin->bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 ) sleep(5); printf(">>>>>>>>>>>>>>>> iguana_bindloop 127.0.0.1:%d bind sock.%d\n",port,coin->bindsock); printf("START ACCEPTING\n"); while ( coin->bindsock >= 0 ) { memset(&pfd,0,sizeof(pfd)); pfd.fd = coin->bindsock; pfd.events = POLLIN; if ( poll(&pfd,1,100) <= 0 ) continue; clilen = sizeof(cli_addr); printf("ACCEPT (%s:%d) on sock.%d\n","127.0.0.1",coin->chain->portp2p,coin->bindsock); sock = accept(coin->bindsock,(struct sockaddr *)&cli_addr,&clilen); if ( sock < 0 ) { printf("ERROR on accept bindsock.%d errno.%d (%s)\n",coin->bindsock,errno,strerror(errno)); continue; } memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits)); expand_ipbits(ipaddr,ipbits); printf("NEWSOCK.%d for %x (%s)\n",sock,ipbits,ipaddr); for (i=0; i<IGUANA_MAXPEERS; i++) { if ( coin->peers.active[i].ipbits == (uint32_t)ipbits && coin->peers.active[i].usock >= 0 ) { printf("found existing peer.(%s) in slot[%d]\n",ipaddr,i); iguana_iAkill(coin,&coin->peers.active[i],0); sleep(1); } } /*if ( (uint32_t)ipbits == myinfo->myaddr.myipbits ) { }*/ if ( (addr= iguana_peerslot(coin,ipbits,0)) == 0 ) { ptr = mycalloc('a',1,sizeof(*ptr)); strcpy(ptr->ipaddr,ipaddr); ptr->ipbits = ipbits; ptr->sock = sock; ptr->port = coin->chain->portp2p; printf("queue PENDING ACCEPTS\n"); queue_enqueue("acceptQ",&coin->acceptQ,&ptr->DL,0); } else { printf("LAUNCH DEDICATED THREAD for %s\n",ipaddr); addr->usock = sock; strcpy(addr->symbol,coin->symbol); iguana_launch(coin,"accept",iguana_dedicatedglue,addr,IGUANA_CONNTHREAD); //iguana_dedicatedloop(coin,addr); } } }
void set_siterates(long z, world_fmt *world, data_fmt *data, option_fmt *options) { long i; mutationmodel_fmt *mumod = &world->mutationmodels[z]; if(mumod->numsiterates==0) { mumod->numsiterates = options->rcategs; mumod->siterates = (double *) mycalloc(mumod->numsiterates,sizeof(double)); mumod->siteprobs = (double *) mycalloc(mumod->numsiterates,sizeof(double)); } for(i=0; i<mumod->numsiterates;i++) { mumod->siterates[i] = options->rrate[i]; mumod->siteprobs[i] = options->probcat[i]; } }
static struct Shdr64Node *addShdr64(struct list *l) { struct Shdr64Node *s = mycalloc(sizeof(struct Shdr64Node)); addtail(l,&(s->n)); return s; }
static time_t bench(thtbl_hash_f f, size_t len) { thtbl_e e; thtbl_t *table; time_t t1, t2; size_t i; char *buf; size_t collisions, searches; if ((e = thtbl_create(&table, len, f, cmp, rem, mycalloc, myfree))) { printf("thtbl_create() failed(%d).\n", e); return 0; } else { t1 = clock(); for (i = 0; i < len * 2; i++) { buf = mycalloc(1, 256); sprintf(buf, "abcdefghijklmnopqrstuvwxyz_value_%010zd", i); e = thtbl_insert(table, buf); } e = thtbl_size(table, &i); thtbl_stat(table, &searches, &collisions); printf("\tsearches: %zd, collisions: %zd (%f%%)\n", searches, collisions, searches ? ((double) collisions / (double) searches) : 0.0); t2 = clock(); thtbl_destroy(table); return t2 - t1; } }
static unsigned long aout_addsym(char *name,taddr value,int bind, int info,int type,int desc,int be) /* add a new symbol, return its symbol table index */ { struct SymbolNode **chain = &aoutsymlist.hashtab[hashcode(name)%SYMHTABSIZE]; struct SymbolNode *sym; while (sym = *chain) chain = &sym->hashchain; /* new symbol table entry */ *chain = sym = mycalloc(sizeof(struct SymbolNode)); if (!name) name = emptystr; sym->name = name; sym->index = aoutsymlist.nextindex++; setval(be,sym->s.n_strx,4,aout_addstr(name)); sym->s.n_type = type; /* GNU binutils don't use BIND_LOCAL/GLOBAL in a.out files! We do! */ sym->s.n_other = ((bind&0xf)<<4) | (info&0xf); setval(be,sym->s.n_desc,2,desc); setval(be,sym->s.n_value,4,value); addtail(&aoutsymlist.l,&sym->n); return sym->index; }
/**************************************************************************** * Copy a string, with allocation. ****************************************************************************/ char * copy_string (char ** target, char * source) { *target = (char *)mycalloc(strlen(source) + 1, sizeof(char)); strcpy(*target, source); return(*target); }
static struct Shdr64Node *addShdr64(void) { struct Shdr64Node *s = mycalloc(sizeof(struct Shdr64Node)); addtail(&shdrlist,&(s->n)); shdrindex++; return s; }
/** Parse command line arguments argc, argv */ ARG_S *parse_args(int argc, const char *argv[]) { ARG_S *arg=mycalloc(1,ARG_S); char *host=NULL; int local=0; ARGOPT_T options[]= { {"help", 'h', M_INT, 0, 1, (void*)print_usage, NULL}, {"detach", 'd',M_INT, 0, 0, &arg->detach, NULL}, {"override",'O',M_INT,0, 0, &arg->override, NULL},
void print_lrt_box(world_fmt *world, MYREAL *param0, MYREAL *param1, long zeros, long elem, char * this_string1, MYREAL like0, MYREAL like1, long df) { // Alternative plot // //--------------------------------------------------------------------- // H0: (p1,p2,p3,..., | LRT = -2(val1 - val2) = val // pi,....,pn) == (v1,v2, | df = x // v3,.... vi,...vn) | Prob = x.xx // | Probc= x.xx // | AIC = x.xxx //--------------------------------------------------------------------- // // LRT MYREAL testval = -2. * (like0 - like1); // standard probability assuming indpendence and range of -inf .. +inf MYREAL chiprob = probchi (df, testval); // probability assuming independence and range of 0 .. inf MYREAL chiprob2 = probchiboundary (testval, zeros, df); // AIC value penalizing for number of paramters long aicparamnum = find_paramnum(world,this_string1); MYREAL aic = -2. * like0 + 2. * aicparamnum; char **box; long size = HUNDRED; // we need at least 7 lines to print the right side of the table /// \todo reallocation of likelihood ratio boxes needs reevaluation long newsize; long i; if(world->options->progress) print_line(stdout,'-',79,CONT); print_line(world->outfile,'-',79,CONT); box = (char **) mycalloc (size, sizeof (char *)); for(i=0; i<size; i++) box[i] = (char *) mycalloc(LRATIO_STRINGS,sizeof(char)); newsize = parse_h0(&box,&size, this_string1,param0,param1,elem,world); print_box(world,box,newsize,like0,like1,testval, chiprob, chiprob2, aic, df, aicparamnum); pdf_print_LRT_box(world,box,newsize,like0,like1,testval, chiprob, chiprob2, aic, df, aicparamnum, &world->page_height, & world->page_width); if(world->options->progress) print_line(stdout,'-',79,CONT); print_line(world->outfile,'-',79,CONT); for(i=0; i<size; i++) myfree(box[i]); myfree(box); }
PBWT *pbwtCreate (int M, int N) { PBWT *p = mycalloc (1, PBWT) ; /* cleared so elements default to 0 */ p->M = M ; p->N = N ; p->aFstart = myalloc (M, int) ; int i ; for (i = 0 ; i < M ; ++i) p->aFstart[i] = i ; return p ; }
void iguana_peersloop(void *ptr) { #ifndef IGUANA_DEDICATED_THREADS struct pollfd fds[IGUANA_MAXPEERS]; struct iguana_info *coin = ptr; struct iguana_peer *addr; uint8_t *bufs[IGUANA_MAXPEERS]; int32_t i,j,n,r,nonz,flag,bufsizes[IGUANA_MAXPEERS],timeout=1; memset(fds,0,sizeof(fds)); memset(bufs,0,sizeof(bufs)); memset(bufsizes,0,sizeof(bufsizes)); while ( 1 ) { while ( coin->peers.shuttingdown != 0 ) { printf("peers shuttingdown\n"); sleep(3); } flag = 0; r = (rand() % coin->MAXPEERS); for (j=n=nonz=0; j<coin->MAXPEERS; j++) { i = (j + r) % coin->MAXPEERS; addr = &coin->peers.active[i]; fds[i].fd = -1; if ( addr->usock >= 0 && addr->dead == 0 && addr->ready != 0 && (addr->startrecv+addr->startsend) != 0 ) { fds[i].fd = addr->usock; fds[i].events = (addr->startrecv != 0) * POLLIN | (addr->startsend != 0) * POLLOUT; nonz++; } } if ( nonz != 0 && poll(fds,coin->MAXPEERS,timeout) > 0 ) { for (j=0; j<coin->MAXPEERS; j++) { i = (j + r) % coin->MAXPEERS; addr = &coin->peers.active[i]; if ( addr->usock < 0 || addr->dead != 0 || addr->ready == 0 ) continue; if ( addr->startrecv == 0 && (fds[i].revents & POLLIN) != 0 && iguana_numthreads(1 << IGUANA_RECVTHREAD) < IGUANA_MAXRECVTHREADS ) { if ( bufs[i] == 0 ) bufsizes[i] = IGUANA_MAXPACKETSIZE, bufs[i] = mycalloc('r',1,bufsizes[i]); flag += iguana_pollrecv(coin,addr,bufs[i],bufsizes[i]); } if ( addr->startsend == 0 && (fds[i].revents & POLLOUT) != 0 && iguana_numthreads(1 << IGUANA_SENDTHREAD) < IGUANA_MAXSENDTHREADS ) { if ( iguana_pollsendQ(coin,addr) == 0 ) flag += iguana_poll(coin,addr); else flag++; } } } if ( flag == 0 ) usleep(1000); } #endif }
void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr) { struct pollfd fds; uint8_t *buf,serialized[64]; int32_t bufsize,flag,timeout = coin->MAXPEERS/64+1; printf("start dedicatedloop.%s\n",addr->ipaddr); bufsize = IGUANA_MAXPACKETSIZE; buf = mycalloc('r',1,bufsize); //printf("send version myservices.%llu\n",(long long)coin->myservices); iguana_send_version(coin,addr,coin->myservices); iguana_queue_send(coin,addr,serialized,"getaddr",0,0,0); //printf("after send version\n"); while ( addr->usock >= 0 && addr->dead == 0 && coin->peers.shuttingdown == 0 ) { flag = 0; memset(&fds,0,sizeof(fds)); fds.fd = addr->usock; fds.events |= POLLOUT; if ( poll(&fds,1,timeout) > 0 ) flag += iguana_pollsendQ(coin,addr); if ( flag == 0 ) { memset(&fds,0,sizeof(fds)); fds.fd = addr->usock; fds.events |= POLLIN; if ( poll(&fds,1,timeout) > 0 ) flag += iguana_pollrecv(coin,addr,buf,bufsize); if ( flag == 0 ) { if ( time(NULL) > addr->pendtime+30 ) { if ( addr->pendblocks > 0 ) addr->pendblocks--; if ( addr->pendhdrs > 0 ) addr->pendhdrs--; addr->pendtime = 0; } if ( addr->pendblocks < IGUANA_MAXPENDING ) { //if ( ((int64_t)coin->R.RSPACE.openfiles * coin->R.RSPACE.size) < coin->MAXRECVCACHE ) { memset(&fds,0,sizeof(fds)); fds.fd = addr->usock; fds.events |= POLLOUT; if ( poll(&fds,1,timeout) > 0 ) flag += iguana_pollQs(coin,addr); } //else printf("%s > %llu coin->IGUANA_MAXRECVCACHE\n",mbstr((int64_t)coin->R.RSPACE.openfiles * coin->R.RSPACE.size),(long long)coin->MAXRECVCACHE); } } if ( flag == 0 )//&& iguana_processjsonQ(coin) == 0 ) usleep(20000);//+ 100000*(coin->blocks.hwmheight > (long)coin->longestchain-coin->minconfirms*2)); } } iguana_iAkill(coin,addr,addr->dead != 0); printf("finish dedicatedloop.%s\n",addr->ipaddr); myfree(buf,bufsize); coin->peers.numconnected--; }
int32_t iguana_rwtx(int32_t rwflag,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t height,int32_t hastimestamp) { int32_t i,len = 0; uint8_t *txstart = serialized; char txidstr[65]; uint32_t timestamp; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); if ( hastimestamp != 0 ) len += iguana_rwnum(rwflag,&serialized[len],sizeof(timestamp),×tamp); len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in); //printf("version.%d ",msg->version); if ( msg->tx_in > 0 && msg->tx_out*100 < maxsize ) { if ( rwflag == 0 ) msg->vins = mycalloc('v',msg->tx_in,sizeof(*msg->vins)); for (i=0; i<msg->tx_in; i++) len += iguana_rwvin(rwflag,&serialized[len],&msg->vins[i]); //printf("numvins.%d\n",msg->tx_in); } else { printf("invalid tx_in.%d\n",msg->tx_in); return(-1); } len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_out); if ( msg->tx_out > 0 && msg->tx_out*32 < maxsize ) { //printf("numvouts.%d ",msg->tx_out); if ( rwflag == 0 ) msg->vouts = mycalloc('v',msg->tx_out,sizeof(*msg->vouts)); for (i=0; i<msg->tx_out; i++) len += iguana_rwvout(rwflag,&serialized[len],&msg->vouts[i]); } else { printf("invalid tx_out.%d\n",msg->tx_out); return(-1); } len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); *txidp = bits256_doublesha256(txidstr,txstart,len); //printf("txid.(%s) len.%d\n",bits256_str(*txidp),len); msg->allocsize = len; Tx_allocated++, Tx_allocsize += len; if ( ((Tx_allocated + Tx_freed) % 10000000) == 0 ) printf("h.%u len.%d (%llu - %llu) %lld (%llu - %llu)\n",height,len,(long long)Tx_allocated,(long long)Tx_freed,(long long)(Tx_allocated - Tx_freed),(long long)Tx_allocsize,(long long)Tx_freesize); return(len); }
static inline void fetch_Single (Single_Item *item) { int i; FT_UShort val; item->coverage = mycalloc (1, sizeof(Coverage_Item)); GSUB_ptr = item->ptr; need(6); item->format = get_UShort(); item->coverage->ptr = item->ptr + get_UShort(); switch (item->format) { case 1: val = get_Short(); item->data.delta = mycalloc (1, sizeof(FT_UShort)); *item->data.delta = val; #ifdef DEBUG warning("Single Substitution Format=1 with Delta=%d at 0x%04x.", val, item->ptr); #endif fetch_Coverage (item->coverage); break; case 2: val = get_UShort(); need(2 * val); item->data.array = mycalloc (1, sizeof(Glyph_Array)); item->data.array->count = val; item->data.array->glyphs = mycalloc (val, sizeof(FT_UShort)); for (i = 0; i < val; i++) item->data.array->glyphs[i] = get_UShort(); #ifdef DEBUG warning("Single Substitution Format=2 with %d Glyphs at 0x%04x.", val, item->ptr); #endif val = fetch_Coverage (item->coverage); if (val != item->data.array->count) oops("Coverage at 0x%04x: covers %d glyphs (should be %d).", item->ptr, val, item->data.array->count); break; default: oops("Single Substitution at 0x%04x: bad Format=%d.", item->ptr, item->format); } add_Single (item); }
/** Second harmonic oscillator. Initialization. */ SHO_T *sho_new(double f0, /**<Resonance frequency*/ double zeta /**<Damping*/){ SHO_T *out=mycalloc(1,SHO_T); const double omega0=2*M_PI*f0; out->dt=0.01/f0; out->c1=2*zeta*omega0; out->c2=omega0*omega0; out->x1=out->x2=0; return out; }
mcobject_async_status_t mcobject_async_init(mcobject_async_t *mcobj_async, size_t chunk_len, size_t obj_size_by_one_chunk, size_t struct_size) { mcobj_async->origin_size = obj_size_by_one_chunk; mcobj_async->struct_size = struct_size; mcobj_async->struct_size_sn = struct_size + sizeof(size_t); mcobj_async->chunks_pos_length = 0; mcobj_async->chunks_pos_size = 128; mcobj_async->chunks_size = chunk_len; mcobj_async->chunks = (mcobject_async_chunk_t**)mycalloc(mcobj_async->chunks_pos_size, sizeof(mcobject_async_chunk_t*)); if(mcobj_async->chunks == NULL) return MCOBJECT_ASYNC_STATUS_CHUNK_ERROR_MEMORY_ALLOCATION; mcobject_async_chunk_up(mcobj_async); mcobj_async->chunk_cache_size = mcobj_async->chunks_size; mcobj_async->chunk_cache = (mcobject_async_chunk_t**)mycalloc(mcobj_async->chunk_cache_size, sizeof(mcobject_async_chunk_t*)); if(mcobj_async->chunk_cache == NULL) return MCOBJECT_ASYNC_STATUS_CHUNK_CACHE_ERROR_MEMORY_ALLOCATION; mcobj_async->nodes_length = 0; mcobj_async->nodes_size = 64; mcobj_async->nodes = (mcobject_async_node_t*)mycalloc(mcobj_async->nodes_size, sizeof(mcobject_async_node_t)); if(mcobj_async->nodes == NULL) return MCOBJECT_ASYNC_STATUS_NODES_ERROR_MEMORY_ALLOCATION; mcobj_async->nodes_cache_length = 0; mcobj_async->nodes_cache_size = mcobj_async->nodes_size; mcobj_async->nodes_cache = (size_t*)mymalloc(mcobj_async->nodes_cache_size * sizeof(size_t)); if(mcobj_async->nodes_cache == NULL) return MCOBJECT_ASYNC_STATUS_NODES_ERROR_MEMORY_ALLOCATION; mcobject_async_clean(mcobj_async); mcobj_async->mcsync = mcsync_create(); return MCOBJECT_ASYNC_STATUS_OK; }
void test_mycalloc() { printf("\n\n\nTest mycalloc : \n"); int *b = (int*)mycalloc(5,sizeof(int*)); int i; for(i=0;i<5;i++) { b[i] = i+1; printf("b[%d] value is %d and it's at %p\n",i+1,b[i],&b[i]); } }
void adjust_temperatures(world_fmt ** universe, long hchains, long step, long steps) { long i; const MYREAL bigger = 1.1; const MYREAL smaller = 0.9; const MYREAL corrsum = steps / HEATCHECKINTERVAL; MYREAL *delta; if(step == 0) { for(i=0; i< hchains; i++) { universe[i]->treeswapcount=0; if(steps < HEATCHECKINTERVAL) universe[i]->averageheat = 1./universe[i]->heat; else universe[i]->averageheat = 0.0; } } else { if ( (step % HEATCHECKINTERVAL ) == 0) { universe[0]->averageheat= 1.0; delta = (MYREAL *) mycalloc(hchains,sizeof(MYREAL)); // FPRINTF(stdout,"\n%f %li\n",1./universe[0]->heat,universe[0]->treeswapcount); for(i=1; i< hchains; i++) { universe[i]->averageheat += (1./(universe[i]->heat * corrsum )); //FPRINTF(stdout,"%f %li\n",1./universe[i]->heat,universe[i]->treeswapcount); delta[i-1] = 1./universe[i]->heat - 1./universe[i-1]->heat; if(delta[i-1] < EPSILON) delta[i-1] = EPSILON; } for(i=1; i< hchains; i++) { if(universe[i-1]->treeswapcount <= HEATSWAPLOW) delta[i-1] *= smaller; else { if(delta[i-1]<1000 && universe[i-1]->treeswapcount >= HEATSWAPHIGH) delta[i-1] *= bigger; } } universe[0]->heat = 1.; universe[0]->treeswapcount=0; for(i=1; i< hchains; i++) { universe[i]->heat = 1./(1./universe[i-1]->heat + delta[i-1]); universe[i]->treeswapcount=0; } myfree(delta); } } }
int picolCallProc(picolInterp *i, int argc, char **argv) { if(i->level>MAXRECURSION) return picolErr(i,"too many nested evaluations (infinite loop?)"); picolCmd *c = picolGetCmd(i,argv[0]); if(!c) return PICOL_ERR; void *pd = c->privdata; if(!pd) return PICOL_ERR; char **x=pd; char *alist=x[0], *body=x[1]; char buf[MAXSTR]; picolCallFrame *cf = mycalloc(1,sizeof(*cf)); int a = 0, done = 0, errcode = PICOL_ERR; #ifndef __arm__ if(!cf) {printf("could not allocate callframe\n"); exit(1);} #else extern void print1(char *str); if(!cf) {dbg_send_str3("could not allocate callframe", 1); return PICOL_ERR;} #endif cf->parent = i->callframe; i->callframe = cf; i->level++; char *p = mystrdup(alist); while(1) { char *start = p; while(*p != ' ' && *p != '\0') p++; if (*p != '\0' && p == start) { p++; continue; } if (p == start) break; if (*p == '\0') done=1; else *p = '\0'; if(EQ(start,"args") && done) { dbg_send_hex2("eq", p - alist); picolSetVar(i,start,picolList1(buf,argc-a-1,argv+a+1)); a = argc-1; break; } if (++a > argc-1) break; picolSetVar(i,start,argv[a]); p++; if (done) break; } if (a == argc-1) errcode = picolEval(i,body); else errcode = picolErr1(i,"wrong # args for '%s'",argv[0]); if (errcode == PICOL_RETURN) errcode = PICOL_OK; i->callframe = cf->parent; myfree(cf); i->level--; return errcode; }
int main () { long categs = 10; MYREAL alpha; MYREAL theta1; MYREAL *rate; MYREAL *probcat; long i; printf ("Enter alpha, theta1, and categs\n"); fscanf (stdin, "%lf%lf%li", &alpha, &theta1, &categs); rate = (MYREAL *) mycalloc (categs + 1, sizeof (MYREAL)); probcat = (MYREAL *) mycalloc (categs + 1, sizeof (MYREAL)); initgammacat (categs, alpha, theta1, rate, probcat); for (i = 0; i < categs; i++) { printf ("%20.20f %20.20f\n", rate[i], probcat[i]); } return 0; }
struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,int32_t datalen) { struct iguana_bundlereq *req; int32_t allocsize; allocsize = (uint32_t)sizeof(*req) + datalen; req = mycalloc(type,1,allocsize); req->allocsize = allocsize; req->addr = addr; req->coin = coin; req->type = type; return(req); }
static struct Symbol64Node *addSymbol64(int be,char *name) { struct Symbol64Node *sn = mycalloc(sizeof(struct Symbol64Node)); addtail(&symlist,&(sn->n)); if (name) { sn->name = name; setval(be,sn->s.st_name,4,addString(&strlist,name)); } symindex++; return sn; }
int get_lane_id(const bam1_t *b) { if(b==NULL) die("get_lane_id: input error"); kstring_t *name = mycalloc(1, kstring_t); name->s = get_pair_name(b); name->l = strlen(name->s); int *fields, n, i; fields = ksplit(name, (int)':', &n); if(n==1) return 0; int lane_id = 0; sscanf(name->s + fields[1], "%d", &lane_id); return lane_id; }
static inline void add_Single (Single_Item *item) { Subst_Item *entry = mycalloc (1, sizeof(Subst_Item)); entry->item = item; if (Subst_last) Subst_last->next = entry; else Subst_list = entry; Subst_last = entry; has_gsub = True; }
/** Prepares the DM caching structs. */ void prep_cachedm(SIM_T *simu){ const PARMS_T *parms=simu->parms; if(!parms->ndm || !parms->sim.cachedm){ warning("No caching is needed\n"); return; } if(!simu->cachedm){ simu->cachedm=mapcellnew(parms->ndm, 1); for(int idm=0; idm<parms->ndm; idm++){ double dx=parms->dm[idm].dx/16; create_metapupil(&simu->cachedm->p[idm], 0, 0, parms->dirs, parms->aper.d, parms->dm[idm].ht+parms->dm[idm].vmisreg, dx, dx, 0, 2, 0,0,0,0); } } //cachedm_ha doesn't help because it is not much faster than ray tracing and //is not parallelized as ray tracing. /*new scheme for ray tracing */ simu->cachedm_prop=mycalloc(parms->ndm,thread_t*); simu->cachedm_propdata=mycalloc(parms->ndm,PROPDATA_T); PROPDATA_T *cpropdata=simu->cachedm_propdata; for(int idm=0; idm<parms->ndm; idm++){ simu->cachedm_prop[idm]=mycalloc(NTHREAD,thread_t); if(simu->dmrealsq){ cpropdata[idm].mapin=simu->dmrealsq->p[idm]; }else{ cpropdata[idm].locin=simu->recon->aloc->p[idm]; cpropdata[idm].phiin=simu->dmreal->p[idm]->p; } cpropdata[idm].mapout=simu->cachedm->p[idm]; cpropdata[idm].alpha=1; cpropdata[idm].displacex0=0; cpropdata[idm].displacey0=0; cpropdata[idm].displacex1=0; cpropdata[idm].displacey1=0; cpropdata[idm].scale=1; thread_prep(simu->cachedm_prop[idm], 0, cpropdata[idm].mapout->ny, NTHREAD, prop, (void*)&cpropdata[idm]); } }
void initlaguerrecat (long categs, MYREAL alpha, MYREAL theta1, MYREAL *rate, MYREAL *probcat) { long i; MYREAL **lgroot; /* roots of GLaguerre polynomials */ MYREAL f, x, xi, y; lgroot = (MYREAL **) mycalloc (categs + 1, sizeof (MYREAL *)); lgroot[0] = (MYREAL *) mycalloc ((categs + 1) * (categs + 1), sizeof (MYREAL)); for (i = 1; i < categs + 1; i++) { lgroot[i] = lgroot[0] + i * (categs + 1); } lgroot[1][1] = 1.0 + alpha; for (i = 2; i <= categs; i++) roots_laguerre (i, alpha, lgroot); /* get roots for L^(a)_n */ /* here get weights */ /* Gamma weights are (1+a)(1+a/2) ... (1+a/n)*x_i/((n+1)^2 [L_{n+1}^a(x_i)]^2) */ f = 1; for (i = 1; i <= categs; i++) f *= (1.0 + alpha / i); for (i = 1; i <= categs; i++) { xi = lgroot[categs][i]; y = glaguerre (categs + 1, alpha, xi); x = f * xi / ((categs + 1) * (categs + 1) * y * y); rate[i - 1] = xi / (1.0 + alpha); probcat[i - 1] = x; } for (i = 0; i < categs; i++) { probcat[i] = LOG (probcat[i]); rate[i] *= theta1; } myfree(lgroot[0]); myfree(lgroot); } /* initgammacat */
int Jacobi_precond_EBE_setup (ParametersType *Parameters, MatrixDataType *MatrixData, FemStructsType *FemStructs, int tag, double *F) { int I; int neq = Parameters->neq; int nel = Parameters->nel; if (tag==1){ MatrixData->invDeaux = mycalloc("invDeaux of 'Jacobi_precond_EBE_setup'",NNOEL*nel,sizeof(double)); MatrixData->invDe = mycalloc("invDe of 'Jacobi_precond_EBE_setup'",nel,sizeof(double*)); for (I=0; I<nel; I++) MatrixData->invDe[I] = &(MatrixData->invDeaux[NNOEL*I]); } for (I=0; I<nel; I++){ MatrixData->invDe[I][0] = 1.0 / (MatrixData->A[I][0]); MatrixData->invDe[I][1] = 1.0 / (MatrixData->A[I][4]); MatrixData->invDe[I][2] = 1.0 / (MatrixData->A[I][8]); /* MatrixData->invDe[I][0] = 1.0 / (1.0 + MatrixData->A[I][0]); MatrixData->invDe[I][1] = 1.0 / (1.0 + MatrixData->A[I][4]); MatrixData->invDe[I][2] = 1.0 / (1.0 + MatrixData->A[I][8]); */ } /* F preconditioning */ double *faux = calloc((neq + 1), sizeof(double)); for (I = 0; I < neq; I++){ faux[I] = F[I]; } faux[neq] = 0.0; F[neq] = 0.0; Jacobi_precond_EBE (Parameters, MatrixData, FemStructs, faux, F); free(faux); return 0; }
/// /// adjust temperatures using a lower and upper bound (temperature=1 and temperature=highest) void adjust_temperatures_bounded(world_fmt ** universe, long hchains, long step, long steps) { //const MYREAL corrsum = steps / HEATCHECKINTERVAL; long i; long deltasum; MYREAL negheat = 0.0; MYREAL *delta; if(step == 0) { for(i=0; i< hchains; i++) { universe[i]->treeswapcount=0; if(steps < HEATCHECKINTERVAL) universe[i]->averageheat = 1./universe[i]->heat; else universe[i]->averageheat = 0.0; } } else { if ( (step % HEATCHECKINTERVAL ) == 0) { universe[0]->averageheat= 1.0; delta = (MYREAL *) mycalloc(hchains,sizeof(MYREAL)); #ifdef DEBUG fprintf(stdout,"\n%i> chain 1: %f %f %li\n",myID, 1./universe[0]->heat,universe[0]->averageheat, universe[0]->treeswapcount); #endif deltasum = 0.0; for(i=1; i< hchains; i++) { universe[i]->averageheat += HEATCHECKINTERVAL * (1./universe[i]->heat - universe[i]->averageheat) / step; #ifdef DEBUG fprintf(stdout,"%i> chain %li: %f %f %li (step=%li (%f))\n", myID, i+1, 1./universe[i]->heat,universe[i]->averageheat, universe[i]->treeswapcount, step, (MYREAL) HEATCHECKINTERVAL/step); #endif delta[i-1] = (MYREAL) universe[i]->treeswapcount; if(delta[i-1] < 1.0) delta[i-1] = 1.0; deltasum += delta[i-1]; } universe[0]->heat = 1.; universe[0]->treeswapcount=0; for(i=1; i < hchains-1; i++) { negheat += delta[i-1]/deltasum; universe[i]->heat = 1. - negheat; universe[i]->treeswapcount=0; } myfree(delta); } } }
gpointer g_malloc_n (gsize n_blocks, gsize n_block_bytes) { if (SIZE_OVERFLOWS (n_blocks, n_block_bytes)) { __android_log_print(ANDROID_LOG_ERROR, "memanalyze", "%s: overflow allocating %" G_GSIZE_FORMAT "*%" G_GSIZE_FORMAT " bytes", G_STRLOC, n_blocks, n_block_bytes); __builtin_unreachable(); } return mycalloc (n_blocks, n_block_bytes); }
int32_t iguana_rwvout(int32_t rwflag,uint8_t *serialized,struct iguana_msgvout *msg) { int32_t len = 0; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->value),&msg->value); len += iguana_rwvarint32(rwflag,&serialized[len],&msg->pk_scriptlen); if ( rwflag == 0 ) msg->pk_script = mycalloc('s',1,msg->pk_scriptlen); len += iguana_rwmem(rwflag,&serialized[len],msg->pk_scriptlen,msg->pk_script); //printf("(%.8f scriptlen.%d) ",dstr(msg->value),msg->pk_scriptlen); //int i; for (i=0; i<msg->pk_scriptlen; i++) // printf("%02x",msg->pk_script[i]); //printf("\n"); return(len); }