示例#1
0
int		print_menu(WINDOW *menu_win, t_ctrl *ctrl, t_list *selected)
{
  t_list	*elem;
  t_pos		*pos;
  int		i;

  i = 0;
  pos = init_pos();
  elem = ctrl->head;
  getmaxyx(menu_win, pos->max_row, pos->max_col);
  wclear(menu_win);
  while (elem)
    {
      where_to_print(elem, pos);
      print_selected(menu_win, elem, pos, selected);
      i = i + 1;
      pos->row = pos->row + 1;
      elem = elem->next;
    }
  if ((pos->col + pos->longer) >= pos->max_col)
    return (1);
  wrefresh(menu_win);
  return (0);
}
示例#2
0
t_wid			*init_surface(t_wid *wid)
{
  GtkWidget		*box[3];

  wid->surface = xmalloc(sizeof(t_surface));
  wid->surface->open = 0;
  wid->in_gen = 0;
  box[1] = gtk_hbox_new(TRUE, 0);
  box[0] = gtk_vbox_new(FALSE, 2);
  box[2] = gtk_vbox_new(FALSE, 2);
  gtk_box_pack_start(GTK_BOX(box[0]),
		     init_prev_next(wid), TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(box[0]),
		     init_pos(wid), FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box[1]),
		     init_change(wid), FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box[2]),
		     init_effect(wid), FALSE, FALSE, 0);
  wid->surface->box = gtk_frame_new("Object");
  gtk_container_add(GTK_CONTAINER(wid->surface->box),
		    GTK_WIDGET(unit_vbox(box, 3, FALSE, 0)));
  wid->data.obj_id = 0;
  return (wid);
}
int main(int argc, const char* argv[]) {
  if (argc <= 1) {
    printf("PLEASE ENTER THREAD NUMBER!\n");
    return 0;
  }
  int nthreads=atoi(argv[1]);
  printf("Number of threads: %d\n", nthreads);
  init_pos();
  double total = 0;
  int N = 3;
  int count;
  for (count = 1; count <= N; count ++) {
    struct timeval begin, end;
    double time_spent;
    
    gettimeofday(&begin, NULL);
    int n;
    for (n=0; n<NUM_TOPICS; n++) {
      // printf("Processing topic %d...\n", topics2011[n][0]);
      heap h_array[nthreads];
      memset(h_array,0,sizeof(h_array));
      struct threadpool *pool;
      pool = threadpool_init(nthreads);
      int i = 0;
      for (i=0; i<nthreads; i++) {
        struct arg_struct *args = malloc(sizeof *args);
        args->topic = n;
        args->startidx = i*(int)(ceil((double)NUM_DOCS / nthreads));
        if ((i+1)*(int)(ceil((double)NUM_DOCS / nthreads)) > NUM_DOCS) {
          args->endidx = NUM_DOCS;
        } else {
          args->endidx = (i+1)*(int)(ceil((double)NUM_DOCS / nthreads));
        }
        args->base = termindexes[nthreads-1][i];
        heap h;
        h_array[i] = h;
        args->h = &h_array[i];
        threadpool_add_task(pool,search,args,0);
      }
      threadpool_free(pool,1);

      heap h_merge;
      heap_create(&h_merge,0,NULL);
      float* min_key_merge;
      int* min_val_merge;
      for (i=0; i<nthreads; i++) {
        float* min_key;
        int* min_val;
        while(heap_delmin(&h_array[i], (void**)&min_key, (void**)&min_val)) {
          int size = heap_size(&h_merge);
          if ( size < TOP_K ) {
            heap_insert(&h_merge, min_key, min_val);
          } else {
            heap_min(&h_merge, (void**)&min_key_merge, (void**)&min_val_merge);
            if (*min_key_merge < *min_key) {
              heap_delmin(&h_merge, (void**)&min_key_merge, (void**)&min_val_merge);
              heap_insert(&h_merge, min_key, min_val);
            }
          }
        }
        heap_destroy(&h_array[i]);
      }

      int rank = TOP_K;
      while (heap_delmin(&h_merge, (void**)&min_key_merge, (void**)&min_val_merge)) {
        printf("MB%02d Q0 %ld %d %f Scan1_pos_multithread_intraquery\n", (n+1), tweetids[*min_val_merge], rank, *min_key_merge);
        rank--;
      }
      heap_destroy(&h_merge);
    }
    
    gettimeofday(&end, NULL);
    time_spent = (double)((end.tv_sec * 1000000 + end.tv_usec) - (begin.tv_sec * 1000000 + begin.tv_usec));
    total = total + time_spent / 1000.0;
  }
  printf("Total time = %f ms\n", total/N);
  printf("Time per query = %f ms\n", (total/N)/NUM_TOPICS);
}
示例#4
0
文件: brown.c 项目: Jumziey/modsim
void run(Par *par)
{
  int i, itherm, nstep, istep, isamp, iblock, st;
  int nsamp = par->nsamp, nblock = par->nblock;
  char wfile[FNAMESIZE];
  Vec *pos, *vel, *force;
  double ekin, epot;
  double v0[NV], v1[NV], v2[NV];
  FILE *estream = NULL;

  // Initialize

  if (par->alpha > 0.0) {
    printf("Seed for random number generator: %d.\n", par->seed);
    init_ran(par->seed);
  }

  pos = malloc(par->n * sizeof(Vec));
  force = malloc(par->n * sizeof(Vec));
  vel = malloc(par->n * sizeof(Vec));

  // Read from file...
  if (par->readfile)
    st = read_conf(par->n, pos, vel, par->readfile);
  else {
    init_pos(par->n, &par->L, pos);
    set_temperature(par->n, par->t, vel);
  }

  // Get file name for writing to.
  get_filename(par, wfile);

  // Open file for writing energy results
  estream = fopen_wfile("efile/", wfile);
  if (!estream) return;

  measure(par->n, &par->L, pos, vel, &epot, &ekin);
  printf("Energy = %g \n", epot);

  double test;
  for(i=0; i<par->ntherm; i++) {
    test = pos[5].x;
    step(par, pos, vel, force);
    if(test == pos[5].x)
      printf("aha!\n");
  }
  //printf("rx ry vx vy = %g  %g  %g  %g\n", pos[0].x, pos[0].y, vel[0].x, vel[0].y);

  // Run and collect values
  printf("\nSimulate %d blocks x %d samples each: ", par->nblock, par->nsamp);
  fflush(stdout);

  init_vcorr(par->n, par->deltat, 0.1, 5.0);

  // Initialize for measuring a histogram of particle distances for
  // distances up to 5.0 and bin size 0.02.
  // init_pcorr(par->n, 0.02, 5.0);
  for (i = 0; i < NV; i++) v1[i] = v2[i] = 0.0;

  nstep = rint(1.0 / par->deltat);
  for (iblock = 0; iblock < nblock; iblock++) {

    for (i = 0; i < NV; i++) v0[i] = 0.0;
    for (isamp = 0; isamp < nsamp; isamp++) {
      for (istep = 0; istep < nstep; istep++) {
	      step(par, pos, vel, force);
	      measure_vcorr(par->n, vel);
      }

      // measure_pcorr(par->n, &par->L, pos);

      measure(par->n, &par->L, pos, vel, &epot, &ekin);
      if (estream) fprintf(estream, "%d %g\n", isamp + nsamp * iblock, epot + ekin);
      v0[0] += epot;
      //v0[1] += ekin;
      //v0[2] += epot + ekin;
    }
    for (i = 0; i < NV; i++) {
      v0[i] /= nsamp;
      v1[i] += v0[i];
      v2[i] += v0[i] * v0[i];
    }

    printf("%d ", iblock + 1);	fflush(stdout);
  }
  printf("\n");

  if (estream) fclose(estream);

  for (i = 0; i < NV; i++) {
    v1[i] /= nblock;
    v2[i] /= nblock;
  }

  // Write configuration to the named file.
  write_conf(par->n, pos, vel, "conf/", wfile);

  // Write velocity correlation results to files.
  write_vcorr(par->n, wfile);
  // write_pcorr(par->n, wfile);

  // Print out some results
  printf("\n");
  printf("v1: %.3f v2: %.3f nblock: %d \n",v1[0],v2[0],nblock);
  print_standard_error("Potential E:  ", v1[0], v2[0], nblock);
  //print_standard_error("Kinetic  E:   ", v1[1], v2[1], nblock);
  //print_standard_error("Total energy: ", v1[2], v2[2], nblock);


  // From the virial theorem:  pressure = N * T + Virial / Dimensionality

  free(vel);
  free(pos);
  
}
示例#5
0
文件: pressure.c 项目: megadoro/LC2
int main(int argc, char *argv[])
{
    /* MD settings */
    N = 108;
    rho = 0.6;
    L = pow(N/rho, 1.0f/DIMENSION);
    double TEMP = 1.22;

    int total_steps = 11e4;

    /* allocate memory */
    obj *particle = (obj*)malloc(N*sizeof(obj));
    int **neighbour = NULL;
    neighbour = create_table(neighbour);

    init_pos(particle,N/2,0.0);
    init_pos(&particle[N/2],N-N/2,0.5);

    init_mom(particle);
    reset_mom(particle,TEMP/T);
    compute_table(particle,neighbour);
    get_acc(particle,neighbour);

    /* print header */
    printf("#N=%d rho=%f L=%f T=%f dt=%f\n", N, rho, L, T, dt);
    printf("#\tt\tH\tU\tK\tT\n");

    double sumU = 0.0f;
    double sumU2 = 0.0f;
    double sumT = 0.0f;
    double sumT2 = 0.0f;
    double sumP = 0.0f;
    double sumP2 = 0.0f;

    FILE *f = fopen("data/pressure.dat","w");
    /* simulation run */
    int i, count = 0;
    for(i = 0; i < total_steps; i++){
        if(!(i%10)) compute_table(particle,neighbour);
        integrate(particle,neighbour);
        if((i*dt<10)&&(i%10==0)) reset_mom(particle,TEMP/T);
        if((i*dt>10)&&(i%100==0)){
            sumU += U;
            sumU2 += U*U;
            sumT += T;
            sumT2 += T*T;

            /* pressure */
            work = work/(DIMENSION*100*N*T)-1;
            sumP += work;
            sumP2 += work*work;
            fprintf(f,"%e\t%e\n",i*dt,work);
            work = 0.0f;

            count++;
        }
        
        printf("%e %e %e %e %e\n", i*dt, H/N, U/N, K/N, T );
    }
    fclose(f);
    printf("# <U/N>=%e\tsqrt[<(U/N-<U/N>)²>]=%e\n", (sumU/count)/N, sqrt(sumU2/count-(sumU/count)*(sumU/count))/N );
    printf("# <T>=%e\tsqrt[<(T-<T>)²>]=%e\n", (sumT/count), sqrt(sumT2/count-(sumT/count)*(sumT/count)) );
    printf("# <P>=%e\tsqrt[<(P-<P>)²>]=%e\n", (sumP/count), sqrt(sumP2/count-(sumP/count)*(sumP/count)) );

    /* exit */
    free(particle);
    destroy_table(neighbour);
    return 0;
}