예제 #1
0
/*-------------------------------------------------------------------------
 * Function:	lite_SC_arrlen
 *
 * Purpose:	Return the length of an array which was allocated
 *		with lite_SC_alloc().
 *
 * Return:	Success:	Length of array.
 *
 *		Failure:	-1
 *
 * Programmer:	Adapted from PACT SCORE
 *		Mar 12, 1996
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
long
lite_SC_arrlen (lite_SC_byte *p) {

   mem_header *space;
   mem_descriptor *desc;
   long nb;

   if (p == NULL) return(-1);

   space = ((mem_header *) p) - 1;
   desc  = &space->block;
   if (!SCORE_BLOCK_P(desc)) return(-1L);

   nb = BLOCK_LENGTH(desc);
   if (nb < 0L) return(-1L);
   else return(nb);
}
예제 #2
0
/*-------------------------------------------------------------------------
 * Function:	lite_SC_free
 *
 * Purpose:	The complementary routine for lite_SC_alloc().  Free all
 *		the space including the counter.
 *
 * Return:	Success:	TRUE
 *
 *		Failure:	FALSE
 *
 * Programmer:	Adapted from PACT SCORE
 *		Mar 12, 1996
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
lite_SC_free (lite_SC_byte *p) {

   mem_header *space;
   mem_descriptor *desc;
   unsigned long nbp;

   if (p == NULL) return(TRUE);

   space = ((mem_header *) p) - 1;
   desc  = &space->block;
   if (!SCORE_BLOCK_P(desc)) return(FALSE);

   if (REF_COUNT(desc) == UNCOLLECT) return(TRUE);

   if (--REF_COUNT(desc) > 0) return(TRUE);

   nbp = BLOCK_LENGTH(desc) + Sz;

   UNASSIGN_BLOCK(desc);

   lite_SC_c_sp_free += (nbp - Sz);
   SC_MEM_COUNT;

   if (_SC_zero_space) {
      memset(space, 0, nbp);
   } else {
#ifdef NEED_MEM_TRACE
      desc->name      = NULL;
      desc->id        = 0L;
      desc->type      = 0;
#endif
      desc->ref_count = 0;
      desc->length    = 0L;
   }

   _SC_prim_free((lite_SC_byte *) space, nbp);
   _SC_n_mem_blocks--;
   return(TRUE);
}
예제 #3
0
파일: md_opt.c 프로젝트: bragilee/project
int main(int argc, char** argv)
{
  //printf("%f\n",GRID_NUM);
  struct timespec diff(struct timespec start, struct timespec end);
  struct timespec time1, time2;
  struct timespec time_stamp;


  int npart,i,j,Num;

  params param;
  mols mol;
  adjacent adj;

  param.npart = N_BODY_NUM;
  param.dt = DT;
  param.eps_lj = EPS;
  param.sig_lj = SIG;

  mol.x = malloc(2*param.npart * sizeof(float));
  mol.v = malloc(2*param.npart * sizeof(float));
  mol.a = malloc(2*param.npart * sizeof(float));
  mol.F = malloc(2*param.npart * sizeof(float));
#if (NEAREST)
  double Blength = BLOCK_LENGTH(GRID_NUM,BOX_SIZE);
  printf("Blength: %lf\n",Blength);
  Num = EST_NUM(GRID_NUM,N_BODY_NUM);
  Num = 4*Num;
  if(!Num)
  {
     Num = 4;
  }
  
  if(N_BODY_NUM < Num)
  {
    Num = N_BODY_NUM;
  }

  adj.n = malloc(sizeof(int) * GRID_NUM * GRID_NUM * Num);
  memset(adj.n,-1,sizeof(int) * GRID_NUM * GRID_NUM *  Num);
  printf("Num: %d\n",Num);
#endif

  npart = init_particles(param.npart, mol.x , mol.v, &param);
  if(npart < param.npart)
  {
    fprintf(stderr, "Could not generate %d particles, Trying %d particles instead\n",param.npart,npart);
    param.npart = npart;
  }
  else
  {
    fprintf(stdout,"Generated %d particles\n",param.npart);
  }

  init_particles_va( param.npart, mol.v,mol.a, &param);

#if(NEAREST)
  printf("Before gridSort\n");
  gridSort(npart, GRID_NUM, Num, adj.n, mol.x);
  printf("After gridSort\n");
#endif

  /*for(i=0;i<npart;i++)
    printf("myBlockNum: %d\n",getMyBlock(param.npart,2*i, adj.n, Num/2));

    for(i=0; i < param.npart; i++)
    {
    printf("nBody-Num: %d Posx: %f Velx: %f Accx: %f Forcex: %f\n",i,
    mol.x[2*i],mol.v[2*i],mol.a[2*i],mol.F[2*i]);
    printf("nBody-Num: %d Posy: %f Vely: %f Accy: %f Forcey: %f\n",i,
    mol.x[2*i+1],mol.v[2*i+1],mol.a[2*i+1],mol.F[2*i+1]);
    }
    */

#if(LINUX)

  clock_gettime(CLOCK_REALTIME, &time1);

#endif
#if(NEAREST)
  compute_forces_nearby(param.npart, adj.n, mol.x, mol.F, GRID_NUM, Num);

#elif(OPT)  
  compute_forces(param.npart,mol.x,mol.F);
#else
    compute_forces_naive(param.npart,mol.x,mol.F);

#endif
  printf("After First ComputeForces\n");
  for(i=0;i<ITERS;i++)
  {
#if(NEAREST)
    gridSort(npart, GRID_NUM, Num, adj.n, mol.x);		    // Added in the gridSort function for each iteration
#endif
    verletInt1(param.npart,param.dt , mol.x, mol.v,mol.a);
    box_reflect(param.npart,mol.x,mol.v,mol.a );
#if(NEAREST)
    compute_forces_nearby(param.npart, adj.n, mol.x, mol.F, GRID_NUM, Num);
#elif(OPT)
    compute_forces(param.npart,mol.x,mol.F);
#else
    compute_forces_naive(param.npart,mol.x,mol.F);
#endif
    verletInt2(param.npart,param.dt, mol.x, mol.v, mol.a);
    memset(mol.F, 0 , 2*param.npart * sizeof(float));
  }

#if(LINUX)

  clock_gettime(CLOCK_REALTIME, &time2);

#endif

  /*
     for(i=0; i < param.npart; i++)
     {
     printf("nBody-Num: %d Posx: %f Velx: %f Accx: %f Forcex: %f\n",i,
     mol.x[2*i],mol.v[2*i],mol.a[2*i],mol.F[2*i]);
     printf("nBody-Num: %d Posy: %f Vely: %f Accy: %f Forcey: %f\n",i,
     mol.x[2*i+1],mol.v[2*i+1],mol.a[2*i+1],mol.F[2*i+1]);
     }
     */

#if(LINUX)

  double blength = BLOCK_LENGTH(GRID_NUM,BOX_SIZE);
  printf("Boxsize: %lf,Blocksize: %lf,MaxBodiesPerBlock: %d\n",BOX_SIZE,blength, maxNumPartPerBlock(blength,SIG));
  time_stamp = diff(time1,time2);
  printf("Execution time: %lf\n",(double)((time_stamp.tv_sec + (time_stamp.tv_nsec/1.0e9))));

#else

  printf("Boxsize: %lf,BlockNum: %lf,MaxBodiesPerBlock: %d\n",BOX_SIZE,GRID_NUM, maxNumPartPerBlock(GRID_NUM,SIG));

#endif

  /*        // test statements for the grid allocation
            int count =0;
            for(i=0;i<GRID_NUM*GRID_NUM*Num/2;i++)
            {
            if(adj.n[i]!=-1)
            {
            count++;
            }
            }
            printf("%d\n",count);

*/
#if(NEAREST)
  free(adj.n);
#endif
  free(mol.x);
  free(mol.v);
  free(mol.a);
  free(mol.F);
  printf("Done\n");

  return 0;
}