Ejemplo n.º 1
0
int Reallocate_Matrix( sparse_matrix **H, int n, int m, char *name, 
		       MPI_Comm comm )
{
  Deallocate_Matrix( *H );
  if( !Allocate_Matrix( H, n, m, comm ) ) {
    fprintf(stderr, "not enough space for %s matrix. terminating!\n", name);
    MPI_Abort( comm, INSUFFICIENT_MEMORY );
  }

#if defined(DEBUG_FOCUS)
  fprintf( stderr, "reallocating %s matrix, n = %d, m = %d\n", name, n, m );
  fprintf( stderr, "memory allocated: %s = %dMB\n", 
	   name, (int)(m * sizeof(sparse_matrix_entry) / (1024*1024)) );
#endif
  return SUCCESS;
}
Ejemplo n.º 2
0
int  Init_Lists( reax_system *system, control_params *control, 
		 simulation_data *data, storage *workspace, reax_list **lists, 
		 mpi_datatypes *mpi_data, char *msg )
{
  int i, num_nbrs;
  int total_hbonds, total_bonds, bond_cap, num_3body, cap_3body, Htop;
  int *hb_top, *bond_top;
  MPI_Comm comm;
  
  comm = mpi_data->world;
  //for( i = 0; i < MAX_NBRS; ++i ) nrecv[i] = system->my_nbrs[i].est_recv;
  //system->N = SendRecv( system, mpi_data, mpi_data->boundary_atom_type, nrecv,
  //		Sort_Boundary_Atoms, Unpack_Exchange_Message, 1 );
  num_nbrs = Estimate_NumNeighbors( system, lists );
  if(!Make_List( system->total_cap, num_nbrs, TYP_FAR_NEIGHBOR, 
		 *lists+FAR_NBRS, comm )){
    fprintf(stderr, "Problem in initializing far nbrs list. Terminating!\n");
    MPI_Abort( comm, INSUFFICIENT_MEMORY );
  }
#if defined(DEBUG_FOCUS)
  fprintf( stderr, "p%d: allocated far_nbrs: num_far=%d, space=%dMB\n",
	   system->my_rank, num_nbrs, 
	   (int)(num_nbrs*sizeof(far_neighbor_data)/(1024*1024)) );
#endif

  Generate_Neighbor_Lists( system, data, workspace, lists );
  bond_top = (int*) calloc( system->total_cap, sizeof(int) );
  hb_top = (int*) calloc( system->local_cap, sizeof(int) );
  Estimate_Storages( system, control, lists,
		     &Htop, hb_top, bond_top, &num_3body, comm );
  
  Allocate_Matrix( &(workspace->H), system->local_cap, Htop, comm );
  workspace->L = NULL;
  workspace->U = NULL;
#if defined(DEBUG_FOCUS)
  fprintf( stderr, "p%d: allocated H matrix: Htop=%d, space=%dMB\n", 
	   system->my_rank, Htop, 
	   (int)(Htop * sizeof(sparse_matrix_entry) / (1024*1024)) );
#endif

  if( control->hbond_cut > 0 ) {
    /* init H indexes */
    total_hbonds = 0;
    for( i = 0; i < system->n; ++i ) {
      system->my_atoms[i].num_hbonds = hb_top[i];
      total_hbonds += hb_top[i];
    }
    total_hbonds = MAX( total_hbonds*SAFER_ZONE, MIN_CAP*MIN_HBONDS );

    if( !Make_List( system->Hcap, total_hbonds, TYP_HBOND, 
		    *lists+HBONDS, comm ) ) {
      fprintf( stderr, "not enough space for hbonds list. terminating!\n" );
      MPI_Abort( comm, INSUFFICIENT_MEMORY );
    } 
#if defined(DEBUG_FOCUS)
    fprintf( stderr, "p%d: allocated hbonds: total_hbonds=%d, space=%dMB\n", 
	     system->my_rank, total_hbonds, 
	     (int)(total_hbonds*sizeof(hbond_data)/(1024*1024)) );
#endif
  }
  
  /* bonds list */
  //Allocate_Bond_List( system->N, bond_top, (*lists)+BONDS );
  //num_bonds = bond_top[system->N-1];
  total_bonds = 0;
  for( i = 0; i < system->N; ++i ) {
    system->my_atoms[i].num_bonds = bond_top[i];
    total_bonds += bond_top[i];
  }
  bond_cap = MAX( total_bonds*SAFE_ZONE, MIN_CAP*MIN_BONDS );
  
  if( !Make_List( system->total_cap, bond_cap, TYP_BOND, 
		  *lists+BONDS, comm ) ) {
    fprintf( stderr, "not enough space for bonds list. terminating!\n" );
    MPI_Abort( comm, INSUFFICIENT_MEMORY );
  }
#if defined(DEBUG_FOCUS)
  fprintf( stderr, "p%d: allocated bonds: total_bonds=%d, space=%dMB\n", 
	   system->my_rank, bond_cap, 
	   (int)(bond_cap*sizeof(bond_data)/(1024*1024)) );
#endif

  /* 3bodies list */
  cap_3body = MAX( num_3body*SAFE_ZONE, MIN_3BODIES );
  if( !Make_List( bond_cap, cap_3body, TYP_THREE_BODY, 
		  *lists+THREE_BODIES, comm ) ){
    fprintf( stderr, "Problem in initializing angles list. Terminating!\n" );
    MPI_Abort( comm, INSUFFICIENT_MEMORY );
  }
#if defined(DEBUG_FOCUS)
  fprintf( stderr, "p%d: allocated 3-body list: num_3body=%d, space=%dMB\n", 
	   system->my_rank, cap_3body, 
	   (int)(cap_3body*sizeof(three_body_interaction_data)/(1024*1024)) );
#endif

#if defined(TEST_FORCES)
  if( !Make_List( system->total_cap, bond_cap*8, TYP_DDELTA, 
		  *lists+DDELTAS, comm ) ) {
    fprintf( stderr, "Problem in initializing dDelta list. Terminating!\n" );
    MPI_Abort( comm, INSUFFICIENT_MEMORY );
  }
  fprintf( stderr, "p%d: allocated dDelta list: num_ddelta=%d space=%ldMB\n", 
	   system->my_rank, bond_cap*30, 
	   bond_cap*8*sizeof(dDelta_data)/(1024*1024) );

  if( !Make_List( bond_cap, bond_cap*50, TYP_DBO, *lists+DBOS, comm ) ) {
    fprintf( stderr, "Problem in initializing dBO list. Terminating!\n" );
    MPI_Abort( comm, INSUFFICIENT_MEMORY );
  }
  fprintf( stderr, "p%d: allocated dbond list: num_dbonds=%d space=%ldMB\n", 
	   system->my_rank, bond_cap*MAX_BONDS*3, 
	   bond_cap*MAX_BONDS*3*sizeof(dbond_data)/(1024*1024) );
#endif

  free( hb_top );
  free( bond_top );

  return SUCCESS;
}
Ejemplo n.º 3
0
Archivo: QEq.c Proyecto: zhang-b/PuReMD
void Init_MatVec( reax_system *system, control_params *control, 
		  simulation_data *data, static_storage *workspace, 
		  list *far_nbrs )
{
  int i, fillin;
  real s_tmp, t_tmp;
  //char fname[100];

  if(control->refactor > 0 && 
     ((data->step-data->prev_steps)%control->refactor==0 || workspace->L==NULL)){
    //Print_Linear_System( system, control, workspace, data->step );
    Sort_Matrix_Rows( workspace->H );
    //fprintf( stderr, "H matrix sorted\n" );
    Calculate_Droptol( workspace->H, workspace->droptol, control->droptol ); 
    //fprintf( stderr, "drop tolerances calculated\n" );
    if( workspace->L == NULL ) {
      fillin = Estimate_LU_Fill( workspace->H, workspace->droptol );
      if( Allocate_Matrix( &(workspace->L), far_nbrs->n, fillin ) == 0 ||
	  Allocate_Matrix( &(workspace->U), far_nbrs->n, fillin ) == 0 ){
	fprintf( stderr, "not enough memory for LU matrices. terminating.\n" );
	exit(INSUFFICIENT_SPACE);
      }
#if defined(DEBUG_FOCUS)
      fprintf( stderr, "fillin = %d\n", fillin );
      fprintf( stderr, "allocated memory: L = U = %ldMB\n",
      	       fillin * sizeof(sparse_matrix_entry) / (1024*1024) );
#endif
    }

    ICHOLT( workspace->H, workspace->droptol, workspace->L, workspace->U );
#if defined(DEBUG_FOCUS)
    fprintf( stderr, "icholt-" );
    //sprintf( fname, "%s.L%d.out", control->sim_name, data->step );
    //Print_Sparse_Matrix2( workspace->L, fname );
    //Print_Sparse_Matrix( U );
#endif
  }

  /* extrapolation for s & t */
  for( i = 0; i < system->N; ++i ) {
    // no extrapolation
    //s_tmp = workspace->s[0][i];
    //t_tmp = workspace->t[0][i];

    // linear
    //s_tmp = 2 * workspace->s[0][i] - workspace->s[1][i];
    //t_tmp = 2 * workspace->t[0][i] - workspace->t[1][i];
      
    // quadratic
    //s_tmp = workspace->s[2][i] + 3 * (workspace->s[0][i]-workspace->s[1][i]);
    t_tmp = workspace->t[2][i] + 3*(workspace->t[0][i]-workspace->t[1][i]);
    
    // cubic
    s_tmp = 4 * (workspace->s[0][i] + workspace->s[2][i]) - 
      (6 * workspace->s[1][i] + workspace->s[3][i] );
    //t_tmp = 4 * (workspace->t[0][i] + workspace->t[2][i]) - 
    //  (6 * workspace->t[1][i] + workspace->t[3][i] );
    
    // 4th order
    //s_tmp = 5 * (workspace->s[0][i] - workspace->s[3][i]) + 
    //  10 * (-workspace->s[1][i] + workspace->s[2][i] ) + workspace->s[4][i];
    //t_tmp = 5 * (workspace->t[0][i] - workspace->t[3][i]) + 
    //  10 * (-workspace->t[1][i] + workspace->t[2][i] ) + workspace->t[4][i];
    
    workspace->s[4][i] = workspace->s[3][i];
    workspace->s[3][i] = workspace->s[2][i]; 
    workspace->s[2][i] = workspace->s[1][i];
    workspace->s[1][i] = workspace->s[0][i];
    workspace->s[0][i] = s_tmp;

    workspace->t[4][i] = workspace->t[3][i];
    workspace->t[3][i] = workspace->t[2][i]; 
    workspace->t[2][i] = workspace->t[1][i];
    workspace->t[1][i] = workspace->t[0][i];
    workspace->t[0][i] = t_tmp;
  }
}