예제 #1
0
int bu_free(struct handle this_handle, void *free_bytes){
    int length=(int)(power(this_handle.bu_depth)-1);
    int i, flag=0;
    /*printf("in buddy free find%p\n",free_bytes);*/
    for(i=length-1;i>0;i--){
        /*printf("i=%d p=%p\n",i,this_handle.bm_head[i].pointer);*/
        if ((this_handle.bm_head[i].pointer==free_bytes)&&(this_handle.bm_head[i].a_used==1)){
            this_handle.bm_head[i].used=0;
            this_handle.bm_head[i].a_used=0;
            flag=1;
            break;
        }
    }
    if(flag==1){
        modBitmap(this_handle.bu_depth-comp_pow(i)+1, this_handle.bm_head, i, 0);
        if(find_buddy(i)!=-1){
            //printf("%d,%d, %d,%d\n",flag,i,find_buddy(i),this_handle.bm_head[find_buddy(i)].used);
            while(this_handle.bm_head[find_buddy(i)].used==0){
                modBitmap(this_handle.bu_depth-comp_pow(find_parents(i))+1, this_handle.bm_head, find_parents(i), 0);
                i=find_parents(i);
                /*printf("%d",i);*/
                if(i==-1){
                    break;
                }
            }
        }
    }
    /*printf("flag=%d\n",flag);*/
    return flag;
}
예제 #2
0
//takes input profile and checks if in graph
//if so, changes node shape to hexagon
//if not, insert new vertex
HASHTBL* process_input_profile(FILE *fp,HASHTBL *brac,char *fullprofile, int fullnum,char *profile,int numhelix, char *diff, int prob) {
  HASHTBL *hash, *temp=NULL;
  char *diff1,*bracket,*difftrip;
  int *val,k1=0,k2=0;
  KEY *parent,*next;

  if (!(temp = hashtbl_create(HASHSIZE,NULL))) {
    fprintf(stderr, "ERROR: hashtbl_create() failed");
    exit(EXIT_FAILURE);
  }

  make_bracket_rep(brac,fullprofile);
  hashtbl_destroy(brac);
  
  profile = sort_input(profile,numhelix);
  //printf("(sorted) profile is %s with fullprofile %s and diff %s\n",profile,fullprofile,diff);

  if ((hash = graph[numhelix-1]) && (hashtbl_get(hash,profile))) {
    if (numhelix == fullnum) {
      //printf("case 1: full profile found in graph\n");
      fullprofile = sort_input(fullprofile,numhelix);
    } else {
    //cannot use find_diff because fullprofile has helices not in table[]
      //puts("case 2: profile found in graph");
      diff = insert_diff(temp,diff);
      bracket = edge_label(temp,profile,fullprofile,fullnum);      
      fprintf(fp,"\"%s\"-> \"%s\" [label =\" %s\\n%s \",fontsize=8,style = dotted];\n",profile,fullprofile,diff,bracket); 
    }
  }
  else {
    /*          
    if (numhelix == fullnum)
      puts("case 3: full profile not found");
    else
      puts("case 4: profile not found");
    */
    for (parent = find_parents(profile); parent; parent = next) {
      diff1 = find_diff(temp,parent->data,profile,&k1,&k2);      
      if (numhelix != fullnum) {
	difftrip = insert_diff(temp,diff);
	diff1 = realloc(diff1,strlen(diff1)+strlen(difftrip)+4);
	//printf("for parent %s, diff1 is now %s, diff is %s and difftrip is %s\n",parent->data,diff1,diff,difftrip);
	sprintf(diff1,"%s\\n%s",diff1,difftrip);
	//printf("Diff is %s for parent %s of profile %s; diff %s for %s\n",diff1,parent->data,profile,difftrip,fullprofile);	
      }
      bracket = edge_label(temp,parent->data,fullprofile,fullnum);
      fprintf(fp,"\"%s\"-> \"%s\" [label =\" %s\\n%s \",fontsize=8,style = dotted];\n",parent->data,fullprofile,bracket,diff1); 
      next = parent->next;
      free(parent);
    }
  }
  //printf("%s has size %d and prob %d\n",fullprofile,fullnum,prob);
  fprintf(fp,"\"%s\" [shape = hexagon];\n",fullprofile);
  val = malloc(sizeof(int)*2);
  val[0] = fullnum;
  val[1] = prob;
  hashtbl_insert(input,fullprofile,val);
  hashtbl_destroy(temp);  

  if (!(brac = hashtbl_create(HASHSIZE,NULL))) {
    fprintf(stderr, "ERROR: hashtbl_create() failed");
    exit(EXIT_FAILURE);
  }
  return brac;
}
예제 #3
0
void read_hlist(char *filename) {
  int64_t n, c=0;
  FILE *input;
  struct halo h = {0};
  char buffer[1024];

  SHORT_PARSETYPE;
  #define NUM_INPUTS 33
  enum short_parsetype stypes[NUM_INPUTS] = 
    { D64, D64, F, F, F,  //  #id desc_id mvir vmax vrms
      F, F, D64, F,       //  Rvir Rs Np x 
      F, F, F, F, F,      // y z vx vy vz 
      F, F, F, F, F,      // JX JY JZ Spin rs_klypin
      F, F, F, F, F,      // M_all M1 M2 M3 M4
      F, F, F, F, F,      // Xoff Voff spin_bullock b_to_a c_to_a 
      F, F, F, F,         // A[x] A[y] A[z] T/|U|
    };
  enum parsetype types[NUM_INPUTS];
  void *data[NUM_INPUTS] = {&(h.id),
                            &(h.descid),
			    &(h.mvir), &(h.vmax), &(h.vrms), &(h.rvir), &(h.rs), 
			    &(h.np), 
			    &(h.pos[0]), &(h.pos[1]), &(h.pos[2]), 
			    &(h.vel[0]), &(h.vel[1]), &(h.vel[2]),
			    &(h.J[0]), &(h.J[1]), &(h.J[2]), &(h.spin),
			    &(h.klypin_rs), &(h.m_all), &(h.alt_m[0]), 
			    &(h.alt_m[1]), &(h.alt_m[2]), &(h.alt_m[3]),
			    &(h.Xoff), &(h.Voff), &(h.bullock_spin), 
			    &(h.b_to_a), &(h.c_to_a), &(h.A[0]), 
			    &(h.A[1]), &(h.A[2]), &(h.kin_to_pot)};
  

  for (n=0; n<NUM_INPUTS; n++) types[n] = stypes[n];
  input = check_fopen(filename, "r");
  while (fgets(buffer, 1024, input)) {
    if (buffer[0] == '#') {
      if (c==0) {
	c=1;
	buffer[strlen(buffer)-1] = 0;
	printf("%s PID\n", buffer);
      } else {
	printf("%s", buffer);
      }
    }
    n = stringparse(buffer, data, (enum parsetype *)types, NUM_INPUTS);
    if (n<NUM_INPUTS) continue;
    if (!(all_halos.num_halos%3000))
      all_halos.halos = check_realloc(all_halos.halos, sizeof(struct halo)*(all_halos.num_halos+3000), "Allocating Halos.");
   
    all_halos.halos[all_halos.num_halos] = h;
    all_halos.num_halos++;
  }
  fclose(input);
  
  all_halos.halos = check_realloc(all_halos.halos, sizeof(struct halo)*all_halos.num_halos, "Allocating Halos.");

  for (n=0; n<all_halos.num_halos; n++) {
    all_halos.halos[n].vmax_r = all_halos.halos[n].rvir;
  }

  find_parents(all_halos.num_halos);

  for (n=0; n<all_halos.num_halos; n++) {
    struct halo *th = all_halos.halos + n;
    printf("%"PRId64" %"PRId64" %.3e %.2f %.2f %.3f %.3f %"PRId64" %.5f %.5f %.5f %.2f %.2f %.2f %.3e %.3e %.3e %.5f %.5f %.4e %.4e %.4e %.4e %.4e %.5f %.2f %.5f %.5f %.5f %.5f %.5f %.5f %.4f %"PRId64"\n",
	   th->id, th->descid, th->mvir, th->vmax, th->vrms, th->rvir, th->rs,
	   th->np, th->pos[0], th->pos[1], th->pos[2], th->vel[0], th->vel[1],
	   th->vel[2], th->J[0], th->J[1], th->J[2], th->spin,
	   th->klypin_rs, th->m_all, th->alt_m[0], th->alt_m[1], th->alt_m[2],
	   th->alt_m[3], th->Xoff, th->Voff, th->bullock_spin, th->b_to_a,
	   th->c_to_a, th->A[0], th->A[1], th->A[2], th->kin_to_pot, th->pid);
  }
}
예제 #4
0
void *buddy_allot(struct handle *handlers, int handlecnt, unsigned long alot_bytes){
    int min_pg=power(handlers[handlecnt].page_size);
    int level, current_level, length;
    int begin;
    int flag=0;     /*if an block is found*/
    int i;
    /*compute the level*/
    if(alot_bytes%min_pg==0){
        if(alot_bytes==min_pg)
            level=handlers[handlecnt].bu_depth;
        else
            level=handlers[handlecnt].bu_depth-comp_pow(alot_bytes/min_pg)+1;
    }
    else
        level=handlers[handlecnt].bu_depth-(comp_pow(alot_bytes/min_pg));

    /*special case for alot_bytes=total length*/
    if(alot_bytes==handlers[handlecnt].n_bytes){
        if(handlers[handlecnt].bm_head[1].used==0){
            modBitmap(handlers[handlecnt].bu_depth,handlers[handlecnt].bm_head,0,1);
            handlers[handlecnt].bm_head[1].a_used=1;
            flag=1;
            return (void*) handlers[handlecnt].memstart;
        }
        else
            printf("no much space to allocate\n");
    }

    /*general cases*/
    if(alot_bytes<handlers[handlecnt].n_bytes){
        length=(int)(power(level-1));
        begin=power(level-1)-1;
        for (i=0;i<length;i=i+1){
            if((handlers[handlecnt].bm_head[begin+i].used==0)&&(handlers[handlecnt].bm_head[find_parents(begin+i)].used==1)){
                //printf(" %d %d %d\n",level,begin,i);
                modBitmap(handlers[handlecnt].bu_depth-level,handlers[handlecnt].bm_head,begin+i,1);
                handlers[handlecnt].bm_head[begin+i].a_used=1;
                flag=1;
                return (void*) handlers[handlecnt].bm_head[begin+i].pointer;
            }
        }
        current_level=level-1;
        while(current_level>0){
            begin=power(current_level-1)-1;
            length=(int)(power(current_level-1));
            for (i=0;i<length;i=i+1){
                if((handlers[handlecnt].bm_head[begin+i].used==0)&&(handlers[handlecnt].bm_head[find_parents(begin+i)].used==1)){
                    //printf("%d,%d,%d\n",current_level, begin,i);
                    modBitmap(handlers[handlecnt].bu_depth-current_level, handlers[handlecnt].bm_head,begin+i, 2);
                    modBitmap(handlers[handlecnt].bu_depth-current_level,handlers[handlecnt].bm_head,find_gradchi((begin+i),level-current_level),1);
                    handlers[handlecnt].bm_head[find_gradchi((power(current_level-1)-2+begin+i),level-current_level)].a_used=1;
                    flag=1;
                    return (void*) handlers[handlecnt].bm_head[power(current_level-1)-2+begin+i].pointer;
                }
            }
            current_level=current_level-1;
        }
        if((current_level==0)&&handlers[handlecnt].bm_head[0].used==0){
            modBitmap(handlers[handlecnt].bu_depth, handlers[handlecnt].bm_head, 0, 2);
            modBitmap(handlers[handlecnt].bu_depth-level, handlers[handlecnt].bm_head, (int)power(level-1)-1, 1);
            handlers[handlecnt].bm_head[power(level-1)-1].a_used=1;
            return (void*) handlers[handlecnt].memstart;
        }
    }
    printf("don't have much space to allocate %d bytes\n",alot_bytes);
    return handlers[handlecnt].memstart-1;
}