diff --git a/sPuReMD/src/allocate.c b/sPuReMD/src/allocate.c index 70946afa7cbcba94a88d56c1df839a7e487c22ac..2531612a65ccfe2019e97bb20b743dc84cabc384 100644 --- a/sPuReMD/src/allocate.c +++ b/sPuReMD/src/allocate.c @@ -28,12 +28,14 @@ /* allocate space for atoms */ void PreAllocate_Space( reax_system * const system, control_params const * const control, - static_storage * const workspace, int n, int first_run ) + static_storage * const workspace, int n ) { int i; - if ( first_run == TRUE ) + if ( system->prealloc_allocated == FALSE ) { + system->prealloc_allocated = TRUE; + system->atoms = scalloc( n, sizeof(reax_atom), "PreAllocate_Space::system->atoms" ); workspace->orig_id = scalloc( n, sizeof(int), diff --git a/sPuReMD/src/allocate.h b/sPuReMD/src/allocate.h index ed8664665c7484f44cd2296c13200057c65b47c5..1716bf42ecb307686a1f6b935f09c7298b1e605e 100644 --- a/sPuReMD/src/allocate.h +++ b/sPuReMD/src/allocate.h @@ -26,7 +26,7 @@ void PreAllocate_Space( reax_system * const, control_params const * const, - static_storage * const, int, int ); + static_storage * const, int ); void Reallocate( reax_system * const, control_params const * const, static_storage * const, reax_list ** const, int ); diff --git a/sPuReMD/src/ffield.c b/sPuReMD/src/ffield.c index 716fcfb67a6a2868eb6dd35c998e502b1df53136..84028b332bee5b0113f46d10fe1eff23024e9e4f 100644 --- a/sPuReMD/src/ffield.c +++ b/sPuReMD/src/ffield.c @@ -26,7 +26,8 @@ #include "tool_box.h" -void Read_Force_Field( FILE *fp, reax_interaction *reax, int first_run ) +void Read_Force_Field( FILE *fp, reax_system * const system, + reax_interaction * const reax ) { char *s; char **tmp; @@ -60,7 +61,7 @@ void Read_Force_Field( FILE *fp, reax_interaction *reax, int first_run ) return; } - if ( first_run == TRUE ) + if ( system->ffield_params_allocated == FALSE ) { reax->gp.l = (real*) smalloc( sizeof(real) * n, "Read_Force_Field::reax->gp-l" ); @@ -97,8 +98,10 @@ void Read_Force_Field( FILE *fp, reax_interaction *reax, int first_run ) fgets( s, MAX_LINE, fp ); fgets( s, MAX_LINE, fp ); - if ( first_run == TRUE ) + if ( system->ffield_params_allocated == FALSE ) { + system->ffield_params_allocated = TRUE; + /* Allocating structures in reax_interaction */ reax->sbp = (single_body_parameters*) scalloc( n, sizeof(single_body_parameters), "Read_Force_Field::reax->sbp" ); diff --git a/sPuReMD/src/ffield.h b/sPuReMD/src/ffield.h index 47b0eb6b4d9fcec9e7fc792f1bd15b97cd022c5d..692e772c18e776bea1c1b508409b41bde90347ff 100644 --- a/sPuReMD/src/ffield.h +++ b/sPuReMD/src/ffield.h @@ -25,7 +25,7 @@ #include "reax_types.h" -void Read_Force_Field( FILE *, reax_interaction *, int ); +void Read_Force_Field( FILE *, reax_system * const, reax_interaction * const ); #endif diff --git a/sPuReMD/src/geo_tools.c b/sPuReMD/src/geo_tools.c index 94472a6d7bd4e76b392b0f234a6c6402b021cb56..068f14088a07f85a14378e06e16e0cfd49ddafff 100644 --- a/sPuReMD/src/geo_tools.c +++ b/sPuReMD/src/geo_tools.c @@ -283,7 +283,7 @@ static int Count_Atoms( reax_system *system, FILE *fp, int geo_format ) void Read_Geo( const char * const geo_file, reax_system* system, control_params *control, - simulation_data *data, static_storage *workspace, int first_run ) + simulation_data *data, static_storage *workspace ) { FILE *geo; int i, n, serial, top; @@ -302,9 +302,9 @@ void Read_Geo( const char * const geo_file, reax_system* system, control_params /* count atoms and allocate storage */ n = Count_Atoms( system, geo, CUSTOM ); - if ( first_run == TRUE || n > system->N ) + if ( system->prealloc_allocated == FALSE || n > system->N ) { - PreAllocate_Space( system, control, workspace, n, first_run ); + PreAllocate_Space( system, control, workspace, n ); } system->N = n; @@ -339,7 +339,7 @@ void Read_Geo( const char * const geo_file, reax_system* system, control_params void Read_PDB( const char * const pdb_file, reax_system* system, control_params *control, - simulation_data *data, static_storage *workspace, int first_run ) + simulation_data *data, static_storage *workspace ) { int i, n, c, c1, pdb_serial, top; FILE *pdb; @@ -370,9 +370,9 @@ void Read_PDB( const char * const pdb_file, reax_system* system, control_params } n = Count_Atoms( system, pdb, PDB ); - if ( first_run == TRUE || n > system->N ) + if ( system->prealloc_allocated == FALSE || n > system->N ) { - PreAllocate_Space( system, control, workspace, n, first_run ); + PreAllocate_Space( system, control, workspace, n ); } system->N = n; @@ -613,7 +613,7 @@ void Write_PDB( reax_system* system, reax_list* bonds, simulation_data *data, void Read_BGF( const char * const bgf_file, reax_system* system, control_params *control, - simulation_data *data, static_storage *workspace, int first_run ) + simulation_data *data, static_storage *workspace ) { FILE *bgf; char **tokens; @@ -662,9 +662,9 @@ void Read_BGF( const char * const bgf_file, reax_system* system, control_params sfclose( bgf, "Read_BGF::bgf" ); - if ( first_run == TRUE || n > system->N ) + if ( system->prealloc_allocated == FALSE || n > system->N ) { - PreAllocate_Space( system, control, workspace, n, first_run ); + PreAllocate_Space( system, control, workspace, n ); } system->N = n; diff --git a/sPuReMD/src/geo_tools.h b/sPuReMD/src/geo_tools.h index af91cb3c349e50c6c30b2191d8db2a943a8cf856..26028db94ea798e8c8e542b3692b20119c3a4a1d 100644 --- a/sPuReMD/src/geo_tools.h +++ b/sPuReMD/src/geo_tools.h @@ -26,16 +26,16 @@ void Read_Geo( const char * const, reax_system *, control_params *, - simulation_data *, static_storage *, int ); + simulation_data *, static_storage * ); void Read_PDB( const char * const, reax_system *, control_params *, - simulation_data *, static_storage *, int ); - -void Read_BGF( const char * const, reax_system *, control_params *, - simulation_data *, static_storage *, int ); + simulation_data *, static_storage * ); void Write_PDB( reax_system *, reax_list *, simulation_data *, control_params *, static_storage *, output_controls * ); +void Read_BGF( const char * const, reax_system *, control_params *, + simulation_data *, static_storage * ); + #endif diff --git a/sPuReMD/src/init_md.c b/sPuReMD/src/init_md.c index 6b8929150277dd33757c3702f0ecbd22d68375f5..caf475ee05180bbca263509e7c9ad781995e8307 100644 --- a/sPuReMD/src/init_md.c +++ b/sPuReMD/src/init_md.c @@ -1318,6 +1318,9 @@ static void Finalize_System( reax_system *system, control_params *control, int i, j, k; reax_interaction *reax; + system->prealloc_allocated = FALSE; + system->ffield_params_allocated = FALSE; + reax = &system->reax_param; Finalize_Grid( system ); diff --git a/sPuReMD/src/reax_types.h b/sPuReMD/src/reax_types.h index 6b5defeecf16afd2e64d0001d1c9f39f1ef53e89..fa5401d1a3df3d672a7103d0c562c584001a3b10 100644 --- a/sPuReMD/src/reax_types.h +++ b/sPuReMD/src/reax_types.h @@ -854,6 +854,10 @@ struct grid struct reax_system { + /* 0 if struct members are NOT allocated, 1 otherwise */ + int prealloc_allocated; + /* 0 if struct members are NOT allocated, 1 otherwise */ + int ffield_params_allocated; /* number of local (non-periodic image) atoms for the current simulation */ int N; /* max. number of local (non-periodic image) atoms across all simulations */ @@ -1765,8 +1769,6 @@ struct spuremd_handle reax_list **lists; /* Output controls */ output_controls *out_control; - /* TRUE for first simulation, FALSE otherwise */ - int first_run; /* TRUE if file I/O for simulation output enabled, FALSE otherwise */ int output_enabled; /* TRUE if reallocation is required due to num. atoms increasing, FALSE otherwise */ diff --git a/sPuReMD/src/restart.c b/sPuReMD/src/restart.c index 4afaa3676065c25c6f3364d8386cc019ade01b54..34ad174c5fa00b503ce9f012facac8e6692f738e 100644 --- a/sPuReMD/src/restart.c +++ b/sPuReMD/src/restart.c @@ -73,7 +73,7 @@ void Write_Binary_Restart( reax_system *system, control_params *control, void Read_Binary_Restart( const char * const fname, reax_system *system, control_params *control, simulation_data *data, - static_storage *workspace, int first_run ) + static_storage *workspace ) { int i; FILE *fres; @@ -108,13 +108,13 @@ void Read_Binary_Restart( const char * const fname, reax_system *system, system->box.box[2][0], system->box.box[2][1], system->box.box[2][2] ); #endif - if ( first_run == TRUE || res_header.N > system->N ) + if ( system->prealloc_allocated == FALSE || res_header.N > system->N ) { - PreAllocate_Space( system, control, workspace, res_header.N, first_run ); + PreAllocate_Space( system, control, workspace, res_header.N ); } system->N = res_header.N; - if ( first_run == TRUE ) + if ( system->prealloc_allocated == FALSE ) { workspace->map_serials = scalloc( MAX_ATOM_ID, sizeof(int), "Read_Binary_Restart::workspace->map_serials" ); @@ -191,7 +191,7 @@ void Write_ASCII_Restart( reax_system *system, control_params *control, void Read_ASCII_Restart( const char * const fname, reax_system *system, control_params *control, simulation_data *data, - static_storage *workspace, int first_run ) + static_storage *workspace ) { int i, n; FILE *fres; @@ -222,13 +222,13 @@ void Read_ASCII_Restart( const char * const fname, reax_system *system, system->box.box[2][0], system->box.box[2][1], system->box.box[2][2] ); #endif - if ( first_run == TRUE || n > system->N ) + if ( system->prealloc_allocated == FALSE || n > system->N ) { - PreAllocate_Space( system, control, workspace, n, first_run ); + PreAllocate_Space( system, control, workspace, n ); } system->N = n; - if ( first_run == TRUE ) + if ( system->prealloc_allocated == FALSE ) { workspace->map_serials = scalloc( MAX_ATOM_ID, sizeof(int), "Read_ASCII_Restart::workspace->map_serials" ); diff --git a/sPuReMD/src/restart.h b/sPuReMD/src/restart.h index 41e221eaafc0c99b558b0116344cb83b45cecef8..0bc101cfa561bb9d3234d7ab97efad08d8d0f6fe 100644 --- a/sPuReMD/src/restart.h +++ b/sPuReMD/src/restart.h @@ -54,11 +54,12 @@ typedef struct #define READ_RESTART_LINE " %d %d %s %lf %lf %lf %lf %lf %lf" void Write_Restart( reax_system *, control_params *, - simulation_data *, static_storage *, output_controls * ); + simulation_data *, static_storage *, output_controls * ); void Read_Binary_Restart( const char * const, reax_system *, control_params *, - simulation_data *, static_storage *, int ); + simulation_data *, static_storage * ); + void Read_ASCII_Restart( const char * const, reax_system *, control_params *, - simulation_data *, static_storage *, int ); + simulation_data *, static_storage * ); #endif diff --git a/sPuReMD/src/spuremd.c b/sPuReMD/src/spuremd.c index a63cf59a2bb45a58228c7a14fef0fa36e16e077a..41fa92f7759836aac66621834b68d3a1c180fe10 100644 --- a/sPuReMD/src/spuremd.c +++ b/sPuReMD/src/spuremd.c @@ -99,37 +99,37 @@ static void Read_Input_Files( const char * const geo_file, const char * const ffield_file, const char * const control_file, reax_system * const system, control_params * const control, simulation_data * const data, static_storage * const workspace, - output_controls * const out_control, int first_run ) + output_controls * const out_control ) { FILE *ffield, *ctrl; ffield = sfopen( ffield_file, "r" ); ctrl = sfopen( control_file, "r" ); - Read_Force_Field( ffield, &system->reax_param, first_run ); + Read_Force_Field( ffield, system, &system->reax_param ); Read_Control_File( ctrl, system, control, out_control ); if ( control->geo_format == CUSTOM ) { - Read_Geo( geo_file, system, control, data, workspace, first_run ); + Read_Geo( geo_file, system, control, data, workspace ); } else if ( control->geo_format == PDB ) { - Read_PDB( geo_file, system, control, data, workspace, first_run ); + Read_PDB( geo_file, system, control, data, workspace ); } else if ( control->geo_format == BGF ) { - Read_BGF( geo_file, system, control, data, workspace, first_run ); + Read_BGF( geo_file, system, control, data, workspace ); } else if ( control->geo_format == ASCII_RESTART ) { - Read_ASCII_Restart( geo_file, system, control, data, workspace, first_run ); + Read_ASCII_Restart( geo_file, system, control, data, workspace ); control->restart = TRUE; } else if ( control->geo_format == BINARY_RESTART ) { - Read_Binary_Restart( geo_file, system, control, data, workspace, first_run ); + Read_Binary_Restart( geo_file, system, control, data, workspace ); control->restart = TRUE; } else @@ -167,6 +167,8 @@ void* setup( const char * const geo_file, const char * const ffield_file, /* second-level allocations */ spmd_handle->system = smalloc( sizeof(reax_system), "Setup::spmd_handle->system" ); + spmd_handle->system->prealloc_allocated = FALSE; + spmd_handle->system->ffield_params_allocated = FALSE; spmd_handle->system->g.allocated = FALSE; spmd_handle->control = smalloc( sizeof(control_params), @@ -198,7 +200,6 @@ void* setup( const char * const geo_file, const char * const ffield_file, spmd_handle->out_control = smalloc( sizeof(output_controls), "Setup::spmd_handle->out_control" ); - spmd_handle->first_run = TRUE; spmd_handle->output_enabled = TRUE; spmd_handle->realloc = TRUE; spmd_handle->callback = NULL; @@ -207,7 +208,7 @@ void* setup( const char * const geo_file, const char * const ffield_file, Read_Input_Files( geo_file, ffield_file, control_file, spmd_handle->system, spmd_handle->control, spmd_handle->data, spmd_handle->workspace, - spmd_handle->out_control, spmd_handle->first_run ); + spmd_handle->out_control ); spmd_handle->system->N_max = (int) CEIL( SAFE_ZONE * spmd_handle->system->N ); @@ -453,14 +454,13 @@ int reset( const void * const handle, const char * const geo_file, spmd_handle->workspace, spmd_handle->out_control ); } - spmd_handle->first_run = FALSE; spmd_handle->realloc = FALSE; spmd_handle->data->sim_id++; Read_Input_Files( geo_file, ffield_file, control_file, spmd_handle->system, spmd_handle->control, spmd_handle->data, spmd_handle->workspace, - spmd_handle->out_control, spmd_handle->first_run ); + spmd_handle->out_control ); if ( spmd_handle->system->N > spmd_handle->system->N_max ) {