Exemplo n.º 1
0
int Init_Workspace( reax_system *system, control_params *control, 
		    storage *workspace, MPI_Comm comm, char *msg )
{ 
  int ret;
  
  ret = Allocate_Workspace( system, control, workspace, 
			    system->local_cap, system->total_cap, comm, msg );
  if( ret != SUCCESS )
    return ret;

  memset( &(workspace->realloc), 0, sizeof(reallocate_data) );
  Reset_Workspace( system, workspace );

  /* Initialize the Taper function */
  Init_Taper( control, workspace, comm );

  return SUCCESS;
}
Exemplo n.º 2
0
void ReAllocate( reax_system *system, control_params *control, 
		 simulation_data *data, storage *workspace, reax_list **lists, 
		 mpi_datatypes *mpi_data )
{
  int i, j, k, p;
  int num_bonds, est_3body, nflag, Nflag, Hflag, mpi_flag, ret, total_send;
  int renbr, newsize;
  reallocate_data *realloc;
  reax_list *far_nbrs;
  sparse_matrix *H;
  grid *g;
  neighbor_proc *nbr_pr;
  mpi_out_data *nbr_data;
  MPI_Comm comm;
  char msg[200];

  realloc = &(workspace->realloc);
  g = &(system->my_grid);
  comm = mpi_data->world;

#if defined(DEBUG)
  fprintf( stderr, "p%d@reallocate: n: %d, N: %d, numH: %d\n",
	   system->my_rank, system->n, system->N, system->numH );
  fprintf( stderr, "p%d@reallocate: local_cap: %d, total_cap: %d, Hcap: %d\n",
	   system->my_rank, system->local_cap, system->total_cap, 
	   system->Hcap);
  fprintf( stderr, "p%d: realloc.num_far: %d\n", 
	   system->my_rank, realloc->num_far );
  fprintf( stderr, "p%d: realloc.H: %d, realloc.Htop: %d\n", 
	   system->my_rank, realloc->H, realloc->Htop );
  fprintf( stderr, "p%d: realloc.Hbonds: %d, realloc.num_hbonds: %d\n", 
	   system->my_rank, realloc->hbonds, realloc->num_hbonds );
  fprintf( stderr, "p%d: realloc.bonds: %d, num_bonds: %d\n", 
	   system->my_rank, realloc->bonds, realloc->num_bonds );
  fprintf( stderr, "p%d: realloc.num_3body: %d\n", 
	   system->my_rank, realloc->num_3body );
#endif
  
  // IMPORTANT: LOOSE ZONES CHECKS ARE DISABLED FOR NOW BY &&'ing with 0!!!
  nflag = 0;
  if( system->n >= DANGER_ZONE * system->local_cap ||
      (0 && system->n <= LOOSE_ZONE * system->local_cap) ) {
    nflag = 1;
    system->local_cap = MAX( (int)(system->n * SAFE_ZONE), MIN_CAP );
  }

  Nflag = 0;
  if( system->N >= DANGER_ZONE * system->total_cap ||
      (0 && system->N <= LOOSE_ZONE * system->total_cap) ) {
    Nflag = 1;
    system->total_cap = MAX( (int)(system->N * SAFE_ZONE), MIN_CAP );
  }

  if( Nflag ) {
    /* system */
#if defined(DEBUG_FOCUS)
    fprintf( stderr, "p%d: reallocating system and workspace -"\
	     "n=%d  N=%d  local_cap=%d  total_cap=%d\n",
	     system->my_rank, system->n, system->N, 
	     system->local_cap, system->total_cap );
#endif
    ret = Allocate_System( system, system->local_cap, system->total_cap, msg );
    if( ret != SUCCESS ) {
      fprintf( stderr, "not enough space for atom_list: total_cap=%d",
	       system->total_cap );
      fprintf( stderr, "terminating...\n" );
      MPI_Abort( comm, INSUFFICIENT_MEMORY );
    }
    
    /* workspace */
    DeAllocate_Workspace( control, workspace );
    ret = Allocate_Workspace( system, control, workspace, system->local_cap, 
			      system->total_cap, comm, msg );
    if( ret != SUCCESS ) {
      fprintf( stderr, "no space for workspace: local_cap=%d total_cap=%d",
	       system->local_cap, system->total_cap );
      fprintf( stderr, "terminating...\n" );
      MPI_Abort( comm, INSUFFICIENT_MEMORY );
    }
  }


  renbr = (data->step - data->prev_steps) % control->reneighbor == 0;
  /* far neighbors */
  if( renbr ) {
    far_nbrs = *lists + FAR_NBRS;

    if( Nflag || realloc->num_far >= far_nbrs->num_intrs * DANGER_ZONE ) {
      if( realloc->num_far > far_nbrs->num_intrs ) {
	fprintf( stderr, "step%d-ran out of space on far_nbrs: top=%d, max=%d",
		 data->step, realloc->num_far, far_nbrs->num_intrs );
	MPI_Abort( comm, INSUFFICIENT_MEMORY );
      }

      newsize = static_cast<int> 
	(MAX( realloc->num_far*SAFE_ZONE, MIN_CAP*MIN_NBRS ));      
#if defined(DEBUG_FOCUS)
      fprintf( stderr, "p%d: reallocating far_nbrs: num_fars=%d, space=%dMB\n", 
	       system->my_rank, (int)(realloc->num_far*SAFE_ZONE), 
	       (newsize*sizeof(far_neighbor_data)/(1024*1024)) );
#endif
      
      Reallocate_Neighbor_List( far_nbrs, system->total_cap, newsize, comm );
      realloc->num_far = 0;
    }
  }

#if defined(PURE_REAX)
  /* qeq coef matrix */
  H = workspace->H;
  if( nflag || realloc->Htop >= H->m * DANGER_ZONE ) {
    if( realloc->Htop > H->m ) {
      fprintf( stderr, 
	       "step%d - ran out of space on H matrix: Htop=%d, max = %d",
	       data->step, realloc->Htop, H->m );
      MPI_Abort( comm, INSUFFICIENT_MEMORY );
    }
#if defined(DEBUG_FOCUS)
    fprintf( stderr, "p%d: reallocating H matrix: Htop=%d, space=%dMB\n", 
	     system->my_rank, (int)(realloc->Htop*SAFE_ZONE), 
	     (int)(realloc->Htop * SAFE_ZONE * sizeof(sparse_matrix_entry) / 
		   (1024*1024)) );
#endif

    newsize = static_cast<int> 
	(MAX( realloc->Htop*SAFE_ZONE, MIN_CAP*MIN_NBRS ));
    Reallocate_Matrix( &(workspace->H), system->local_cap, 
		       newsize, "H", comm );
    //Deallocate_Matrix( workspace->L );
    //Deallocate_Matrix( workspace->U );
    workspace->L = NULL;
    workspace->U = NULL;
    realloc->Htop = 0;
  }
#endif /*PURE_REAX*/

  /* hydrogen bonds list */
  if( control->hbond_cut > 0 ) { 
    Hflag = 0;
    if( system->numH >= DANGER_ZONE * system->Hcap || 
	(0 && system->numH <= LOOSE_ZONE * system->Hcap) ) {
      Hflag = 1;
      system->Hcap = MAX( system->numH * SAFER_ZONE, MIN_CAP );
    }

    if( Hflag || realloc->hbonds ) {
      ret = Reallocate_HBonds_List( system, (*lists)+HBONDS, comm );
      realloc->hbonds = 0;
#if defined(DEBUG_FOCUS)
      fprintf(stderr, "p%d: reallocating hbonds: total_hbonds=%d space=%dMB\n",
	      system->my_rank, ret, (int)(ret*sizeof(hbond_data)/(1024*1024)));
#endif
    }
  }

  /* bonds list */
  num_bonds = est_3body = -1;
  if( Nflag || realloc->bonds ){
    Reallocate_Bonds_List( system, (*lists)+BONDS, &num_bonds, 
			   &est_3body, comm );
    realloc->bonds = 0;
    realloc->num_3body = MAX( realloc->num_3body, est_3body );
#if defined(DEBUG_FOCUS)
    fprintf( stderr, "p%d: reallocating bonds: total_bonds=%d, space=%dMB\n", 
	     system->my_rank, num_bonds, 
	     (int)(num_bonds*sizeof(bond_data)/(1024*1024)) );
#endif
  }

  /* 3-body list */
  if( realloc->num_3body > 0 ) {
#if defined(DEBUG_FOCUS)
    fprintf( stderr, "p%d: reallocating 3body list: num_3body=%d, space=%dMB\n",
	     system->my_rank, realloc->num_3body, 
	     (int)(realloc->num_3body * sizeof(three_body_interaction_data) / 
		   (1024*1024)) );
#endif
    Delete_List( (*lists)+THREE_BODIES, comm );
    
    if( num_bonds == -1 )
      num_bonds = ((*lists)+BONDS)->num_intrs;

    realloc->num_3body = (int)(MAX(realloc->num_3body*SAFE_ZONE, MIN_3BODIES));

    if( !Make_List( num_bonds, realloc->num_3body, TYP_THREE_BODY, 
		    (*lists)+THREE_BODIES, comm ) ) {
      fprintf( stderr, "Problem in initializing angles list. Terminating!\n" );
      MPI_Abort( comm, CANNOT_INITIALIZE );
    }
    realloc->num_3body = -1;
  }

#if defined(PURE_REAX)
  /* grid */
  if( renbr && realloc->gcell_atoms > -1 ) {
#if defined(DEBUG_FOCUS)
    fprintf(stderr, "reallocating gcell: g->max_atoms: %d\n", g->max_atoms);
#endif
    for( i = g->native_str[0]; i < g->native_end[0]; i++ )
      for( j = g->native_str[1]; j < g->native_end[1]; j++ )
	for( k = g->native_str[2]; k < g->native_end[2]; k++ ) {
	  // reallocate g->atoms
	  sfree( g->cells[i][j][k].atoms, "g:atoms" );  
	  g->cells[i][j][k].atoms = (int*) 
	    scalloc( realloc->gcell_atoms, sizeof(int), "g:atoms", comm);
	}
    realloc->gcell_atoms = -1;
  }

  /* mpi buffers */
  // we have to be at a renbring step - 
  // to ensure correct values at mpi_buffers for update_boundary_positions
  if( !renbr )
    mpi_flag = 0;
  // check whether in_buffer capacity is enough
  else if( system->max_recved >= system->est_recv * 0.90 ) 
    mpi_flag = 1;
  else {
    // otherwise check individual outgoing buffers
    mpi_flag = 0;
    for( p = 0; p < MAX_NBRS; ++p ) {
      nbr_pr   = &( system->my_nbrs[p] );
      nbr_data = &( mpi_data->out_buffers[p] );
      if( nbr_data->cnt >= nbr_pr->est_send * 0.90 ) {
	mpi_flag = 1;
	break;
      }
    }
  }

  if( mpi_flag ) {
#if defined(DEBUG_FOCUS)
    fprintf( stderr, "p%d: reallocating mpi_buf: old_recv=%d\n",
	     system->my_rank, system->est_recv );
    for( p = 0; p < MAX_NBRS; ++p ) 
      fprintf( stderr, "p%d: nbr%d old_send=%d\n", 
	       system->my_rank, p, system->my_nbrs[p].est_send );
#endif
    /* update mpi buffer estimates based on last comm */
    system->est_recv = MAX( system->max_recved*SAFER_ZONE, MIN_SEND );
    system->est_trans = 
      (system->est_recv * sizeof(boundary_atom)) / sizeof(mpi_atom);
    total_send = 0;
    for( p = 0; p < MAX_NBRS; ++p ) {
      nbr_pr   = &( system->my_nbrs[p] );
      nbr_data = &( mpi_data->out_buffers[p] );
      nbr_pr->est_send = MAX( nbr_data->cnt*SAFER_ZONE, MIN_SEND );
      total_send += nbr_pr->est_send;
    }
#if defined(DEBUG_FOCUS)
    fprintf( stderr, "p%d: reallocating mpi_buf: recv=%d send=%d total=%dMB\n",
	     system->my_rank, system->est_recv, total_send,
	     (int)((system->est_recv+total_send)*sizeof(boundary_atom)/
		   (1024*1024)));
    for( p = 0; p < MAX_NBRS; ++p ) 
      fprintf( stderr, "p%d: nbr%d new_send=%d\n", 
	       system->my_rank, p, system->my_nbrs[p].est_send );
#endif

    /* reallocate mpi buffers */
    Deallocate_MPI_Buffers( mpi_data );
    ret = Allocate_MPI_Buffers( mpi_data, system->est_recv, 
				system->my_nbrs, msg );
    if( ret != SUCCESS ) {
      fprintf( stderr, "%s", msg );
      fprintf( stderr, "terminating...\n" );
      MPI_Abort( comm, INSUFFICIENT_MEMORY );
    }
  }
#endif /*PURE_REAX*/

#if defined(DEBUG_FOCUS) 
  fprintf( stderr, "p%d @ step%d: reallocate done\n", 
	   system->my_rank, data->step );
  MPI_Barrier( comm );
#endif
}