Beispiel #1
0
void reading(int *reader_id)
{
    while(1){
        pthread_mutex_lock(&mutex);
        rc++;
        if(rc == 1) pthread_mutex_lock(&db);
        pthread_mutex_unlock(&mutex);
        read_data_base(*reader_id);
        pthread_mutex_lock(&mutex);
        rc--;
        if(rc == 0) pthread_mutex_unlock(&db);
        pthread_mutex_unlock(&mutex);
        use_data_read(*reader_id);
    }
}
void reader(void) 
{
	int item;

	while(1 == 1) {
		down(&mutex);
		rc = rc + 1;
		if (rc == 1) down(&db);
		up(&mutex);
		item = read_data_base();
		down(&mutex);
		rc = rc - 1;
		if (rc == 0) up(&db);
		up(&mutex);
		use_data(item);
	}
}
Beispiel #3
0
void control_surf_params(MDSURFACE *surface, 
    FILENAME_PARSE *filename_parse,
    int natm_typ, NAME atm_typ[], 
    double *tot_memory)

  /*======================================================================*/
  /*  Begin routine */
{/*begin routine*/
  /*======================================================================*/
  /*          Local variable declarations                                */

  DATA_BASE_ENTRIES *surf_base;          /* Lst: Database parameters    */
  double *eps,*sig;                      /* Lst: Lennard-Jones params   */

  int    *surf_label;
  int    *ifound,*isearch,*igood;        /* Lst: found,search goodness flags*/
  double now_mem;                        /* Num: Memory allocated here  */
  char   typ[5];
  int    nbase,nbase2,ibase_want;
  CATM_LAB *csurf,*csurf_base;

  char   *fun_key;
  int    num_fun_dict;
  DICT_WORD *fun_dict;

  int    i,iii;   
  int    ifirst;
  int    nsearch,natm_srch;
  int    nsplin_tot,nsplin_mall_tot;
  int    natm_typ_mall;

  char *surface_type   = surface->surface_type;
  int    nsplin        = surface->nsplin_surf;
  char *user_surf_name = filename_parse->user_surf_name;
  char *def_surf_name  = filename_parse->def_surf_name;
  double *zcut_off,*zmin_spl;

  /*======================================================================*/
  /* 0) Write to screen                                                   */

  PRINTF("\n");
  PRINT_LINE_STAR;
  PRINTF(" Searching the data bases (both user defined and default)\n");
  PRINTF(" for the %d surface interaction sets\n", natm_typ);
  PRINT_LINE_DASH; PRINTF("\n");

  /*======================================================================*/
  /*  I) Malloc the memory                                                 */

  natm_typ_mall = natm_typ; 
  if((natm_typ_mall!=0)&&((natm_typ_mall %2)==0)){natm_typ_mall +=1;}

  surf_label  = (int *) cmalloc(natm_typ_mall*sizeof(int),"control_surf_params")-1;
  eps         = (double *) cmalloc(natm_typ_mall*sizeof(double),"control_surf_params")-1;
  sig         = (double *) cmalloc(natm_typ_mall*sizeof(double),"control_surf_params")-1;
  fun_key     = (char *)cmalloc(MAXWORD*sizeof(char),"control_surf_params");  
  csurf       = (CATM_LAB *)cmalloc(natm_typ*sizeof(CATM_LAB),"control_surf_params")-1;  
  ifound      = (int *)cmalloc(natm_typ*sizeof(int),"control_surf_params")-1;
  isearch     = (int *)cmalloc(natm_typ*sizeof(int),"control_surf_params")-1;
  igood       = (int *)cmalloc(natm_typ*sizeof(int),"control_surf_params")-1;

  surface->zcut_off = (double *) cmalloc(natm_typ_mall*sizeof(double),"control_surf_params")-1;
  surface->zmin_spl = (double *) cmalloc(natm_typ_mall*sizeof(double),"control_surf_params")-1;

  zcut_off = surface->zcut_off;
  zmin_spl = surface->zmin_spl;

  /*======================================================================*/
  /*  II) Set up the data structures                                      */


  ifirst =1;
  set_potfun_dict(&fun_dict,&num_fun_dict,ifirst);
  for(i=1;i <= natm_typ; i++) {
    strcpy(csurf[i].atm1,surface_type);
    strcpy(csurf[i].atm2,atm_typ[i]);
  }/*endfor*/
  for(i=1;i<=natm_typ;i++){ifound[i]=0;}
  for(i=1;i<=natm_typ;i++){igood[i]=6;}

  /*======================================================================*/
  /*  III) Search the user defined data base                             */


  natm_srch = 2;
  if(strlen(user_surf_name) != 0){
    nsearch    = 1;
    ibase_want = 8;  /* functional keyword index */
    count_data_base(user_surf_name,fun_dict,num_fun_dict,
        &nbase,ibase_want);
    if(nbase>0){
      nbase2 = 2*nbase;
      surf_base  = (DATA_BASE_ENTRIES *)
        cmalloc(nbase2*sizeof(DATA_BASE_ENTRIES),"control_surf_params")-1;
      csurf_base = (CATM_LAB *)cmalloc(nbase2*sizeof(CATM_LAB),"control_surf_params")-1;
      read_data_base(user_surf_name,fun_dict,num_fun_dict,
          surf_base,csurf_base,ibase_want,nbase);
      search_base(nbase,nbase2,csurf_base,natm_typ,csurf,igood,ifound,
          isearch,nsearch,natm_srch,user_surf_name);
      assign_base_surf(surf_base,nbase,ifound,natm_typ,sig,eps,surf_label,
          zcut_off,zmin_spl,isearch,nsearch);
      cfree(&surf_base[1],"control_surf_params");
      cfree(&csurf_base[1],"control_surf_params");
    }/*endif*/
  }/*endif*/

  /*======================================================================*/
  /*  IV) Search the default defined data base                             */

  if(strlen(def_surf_name) != 0){
    nsearch    = 2;
    ibase_want = 8;
    count_data_base(def_surf_name,fun_dict,num_fun_dict,
        &nbase,ibase_want);
    if(nbase>0){
      nbase2    = 2*nbase;
      surf_base = (DATA_BASE_ENTRIES *)
        cmalloc(nbase*sizeof(DATA_BASE_ENTRIES),"control_surf_params")-1;
      csurf_base = (CATM_LAB *)cmalloc(nbase2*sizeof(CATM_LAB),"control_surf_params")-1;
      read_data_base(def_surf_name,fun_dict,num_fun_dict,
          surf_base,csurf_base,ibase_want,nbase);
      search_base(nbase,nbase2,csurf_base,natm_typ,csurf,igood,ifound,
          isearch,nsearch,natm_srch,def_surf_name);
      assign_base_surf(surf_base,nbase,ifound,natm_typ,sig,eps,surf_label,
          zcut_off,zmin_spl,isearch,nsearch);
      cfree(&surf_base[1],"control_surf_params");
      cfree(&csurf_base[1],"control_surf_params");
    }/*endif*/
  }/*endif*/


  /*======================================================================*/
  /* V) Check list for missing entries                                    */

  strcpy(typ,"surf");
  atmlst_not_found(natm_typ,csurf,ifound,natm_srch,typ);

  /*======================================================================*/
  /* VI) Allocate spline arrays                                           */

  nsplin_tot          = nsplin*natm_typ;
  surface->nsplin_tot = nsplin_tot;
  now_mem      = ( (double)( 
        2*nsplin_tot*(sizeof(double)) + 
        3*natm_typ*(sizeof(double)) 
        ))*1.e-06;
  *tot_memory += now_mem;

  PRINTF("Surface potential allocation: %g Mbytes; Total memory: %g Mbytes\n",
      now_mem,*tot_memory);

  nsplin_mall_tot = nsplin_tot;
  if((nsplin_mall_tot!=0)&&((nsplin_mall_tot % 2)==0)){nsplin_mall_tot += 1;}

  surface->surface_pot  = (double *)cmalloc(nsplin_mall_tot*sizeof(double),"control_surf_params")-1;
  surface->surface_forc = (double *)cmalloc(nsplin_mall_tot*sizeof(double),"control_surf_params")-1;

  surface->dzi_spl      = (double *) cmalloc(natm_typ_mall*sizeof(double),"control_surf_params")-1;
  surface->dz_spl       = (double *) cmalloc(natm_typ_mall*sizeof(double),"control_surf_params")-1;

  /*=======================================================================*/
  /* VII) Set up the splines for the surface potential                     */
  /*      energy and forces                                                */

  set_surf_splin(sig,eps,surf_label,surface,natm_typ);

  /*=======================================================================*/
  /*  IX) Free temporary memory                                            */

  cfree(&surf_label[1],"control_surf_params");
  cfree(&eps[1],"control_surf_params");
  cfree(&sig[1],"control_surf_params");
  cfree(fun_key,"control_surf_params");
  cfree(&csurf[1],"control_surf_params");
  cfree(&ifound[1],"control_surf_params");
  cfree(&isearch[1],"control_surf_params");
  cfree(&igood[1],"control_surf_params");
  cfree(&fun_dict[1],"control_surf_params");

  /*=======================================================================*/
  /* X) Write to screen                                                    */

  PRINTF("\n");
  PRINT_LINE_DASH;
  PRINTF("Completed the data bases searches\n");
  PRINT_LINE_STAR;
  PRINTF("\n");

  /*----------------------------------------------------------------------*/
} /* end routine */