예제 #1
0
int main (int argc, char ** argv) {
    printf("Call Init\n");
    int *ran=(int *)malloc(H1*H2*sizeof(int));
    hclib::launch([=]() {
        int i = 0;
        // This is ok to have these on stack because this
        // code is alive until the end of the program.

        init_ran(ran, H1*H2);
        hclib::finish([=]() {
            loop_domain_t loop0 = {0,H1,1,T1};
            loop_domain_t loop1 = {0,H2,1,T2};
            loop_domain_t loop[2] = {loop0, loop1};
            hclib::forasync2D(loop, [=](int idx1, int idx2) {
                    assert(ran[idx1*H2+idx2] == -1);
                    ran[idx1*H2+idx2] = idx1*H2+idx2; }, FORASYNC_MODE_FLAT);
        });
    });

    printf("Check results: ");
    int i = 0;
    while(i < H1*H2) {
        assert(ran[i] == i);
        i++;
    }
    free(ran);
    printf("OK\n");
    return 0;
}
예제 #2
0
int main (int argc, char ** argv) {
    printf("Call Init\n");
    hclib::launch([]() {
        // This is ok to have these on stack because this
        // code is alive until the end of the program.
        hclib::finish([]() {
            int i = 0;
            int indices [NB_ASYNC];
            init_ran(ran, NB_ASYNC);

            while (i < NB_ASYNC) {
                indices[i] = i;
                hclib::async([=](){
                    int index = indices[i];
                    assert(ran[index] == -1);
                    ran[index] = index;
                });
                i++;
            }
        });
    });
    printf("Check results: ");
    int i = 0;
    while(i < NB_ASYNC) {
        assert(ran[i] == i);
        i++;
    }
    printf("OK\n");
    return 0;
}
예제 #3
0
int main (int argc, char ** argv) {
    printf("Call Init\n");
    hclib_init(&argc, argv);
    int i = 0;
    int *ran=(int *)malloc(H1*H2*sizeof(int));
    // This is ok to have these on stack because this
    // code is alive until the end of the program.

    init_ran(ran, H1*H2);
    loop_domain_t loop0 = {0,H1,1,T1};
    loop_domain_t loop1 = {0,H2,1,T2};
    loop_domain_t loop[2] = {loop0, loop1};
    forasync(forasync_fct2,(void*)(ran),NULL, NULL,NULL,2,loop, FORASYNC_MODE_FLAT);

    printf("Call Finalize\n");
    hclib_finalize();
    printf("Check results: ");
    i=0;
    while(i < H1*H2) {
        assert(ran[i] == i);
        i++;
    }
    printf("OK\n");
    return 0;
}
예제 #4
0
int main (int argc, char ** argv) {
    printf("Call Init\n");
    hclib_init(&argc, argv);
    int i = 0;
    // This is ok to have these on stack because this
    // code is alive until the end of the program.
    int indices [NB_ASYNC];
    init_ran(ran, NB_ASYNC);
    while(i < NB_ASYNC) {
        indices[i] = i;
        //Note: Forcefully pass the address we want to write to as a void **
        async(async_fct, (void*) (indices+i), NULL, NULL, NO_PROP);
        i++;
    }
    printf("Call Finalize\n");
    hclib_finalize();
    printf("Check results: ");
    i=0;
    while(i < NB_ASYNC) {
        assert(ran[i] == i);
        i++;
    }
    printf("OK\n");
    return 0;
}
예제 #5
0
void entrypoint(void *arg) {
    volatile int * indices = (int *) malloc(sizeof(int)*NB_ASYNC);
    ran = (int *) malloc(sizeof(int)*NB_ASYNC);
    init_ran(ran, NB_ASYNC);

    hclib_start_finish();

    spawn_async(indices, 0);

    hclib_end_finish();

    printf("Call Finalize\n");
}
예제 #6
0
void entrypoint(void *arg) {
    int *ran = (int *)arg;
    // This is ok to have these on stack because this
    // code is alive until the end of the program.

    init_ran(ran, H1*H2);
    loop_domain_t loop0 = {0,H1,1,T1};
    loop_domain_t loop1 = {0,H2,1,T2};
    loop_domain_t loop[2] = {loop0, loop1};

    hclib_start_finish();
    hclib_forasync(forasync_fct2, (void*)(ran), NULL, 2, loop,
            FORASYNC_MODE_RECURSIVE);
    hclib_end_finish();

    printf("Call Finalize\n");
}
예제 #7
0
int main (int argc, char ** argv) {
    printf("Call Init\n");
    int mid = NB_ASYNC/2;
    hclib::launch([&mid]() {
        int i = 0;
        int indices [NB_ASYNC];

        hclib::finish([=, &i, &indices]() {

            // This is ok to have these on stack because this
            // code is alive until the end of the program.
            init_ran(ran, NB_ASYNC);
            printf("Go over [%d:%d]\n", i, mid);
            while(i < mid) {
                indices[i] = i;
                hclib::async([=]() { int index = indices[i];
                    assert(ran[index] == -1); ran[index] = index; });
                i++;
            }
        });

        printf("Midway\n");
        assert_done(0, mid);
        printf("Go over [%d:%d]\n", i, NB_ASYNC);
        while(i < NB_ASYNC) {
            indices[i] = i;
            //Note: Forcefully pass the address we want to write to as a void **
            hclib::async([=]() { int index = indices[i];
                assert(ran[index] == -1); ran[index] = index; });
            i++;
        }
    });
    printf("Check results: ");
    assert_done(mid, NB_ASYNC);
    printf("OK\n");
    return 0;
}
예제 #8
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);
  
}