Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breakout deallocation calls into simpler smaller files #2070

Open
wants to merge 20 commits into
base: release-v4.6.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clean
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ endif

( cd tools/CodeBase ; make clean )

( cd inc ; /bin/rm -f *.inc namelist.default commit_decl )
( cd inc ; /bin/rm -f *.inc namelist.default commit_decl *.o *.F )

find . -name \*.dSYM -exec rm -rf {} \; >& /dev/null

Expand Down
5 changes: 2 additions & 3 deletions frame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ target_sources(
module_alloc_space_7.F
module_alloc_space_8.F
module_alloc_space_9.F

${CMAKE_BINARY_DIR}/frame/module_state_description.F # GENERATED

${nl_dyn_source} # GENERATED

clog.c
Expand Down Expand Up @@ -166,4 +165,4 @@ set_source_files_properties(
install(
FILES ${WRF_INCLUDE_FILES}
DESTINATION include/${FOLDER_COMPILE_TARGET}
)
)
20 changes: 17 additions & 3 deletions frame/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,21 @@ NLOBJS =\
nl_set_4_routines.o \
nl_set_5_routines.o \
nl_set_6_routines.o \
nl_set_7_routines.o
nl_set_7_routines.o

DEALOBJS =\
../inc/deallocs_0.o \
../inc/deallocs_1.o \
../inc/deallocs_2.o \
../inc/deallocs_3.o \
../inc/deallocs_4.o \
../inc/deallocs_5.o \
../inc/deallocs_6.o \
../inc/deallocs_7.o \
../inc/deallocs_8.o \
../inc/deallocs_9.o \
../inc/deallocs_10.o \
../inc/deallocs_11.o

OBJS = \
wrf_num_bytes_between.o \
Expand All @@ -81,8 +95,8 @@ include ../configure.wrf

LIBTARGET = framework
TARGETDIR = ./
$(LIBTARGET) : $(MODULES) $(OBJS) $(SPECIAL) $(NLOBJS) $(ALOBJS)
$(AR) $(ARFLAGS) ../main/$(LIBWRFLIB) $(MODULES) $(OBJS) $(NLOBJS) $(ALOBJS)
$(LIBTARGET) : $(MODULES) $(OBJS) $(SPECIAL) $(NLOBJS) $(ALOBJS) $(DEALOBJS)
$(AR) $(ARFLAGS) ../main/$(LIBWRFLIB) $(MODULES) $(OBJS) $(NLOBJS) $(ALOBJS) $(DEALOBJS)
$(RANLIB) ../main/$(LIBWRFLIB)

nl_set_0_routines.o : nl_access_routines.F module_configure.o
Expand Down
5 changes: 0 additions & 5 deletions frame/module_domain.F
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ SUBROUTINE get_ijk_from_subgrid ( grid , &
END SUBROUTINE get_ijk_from_subgrid
#endif


! Default version ; Otherwise module containing interface to DM library will provide

SUBROUTINE wrf_patch_domain( id , domdesc , parent, parent_id , parent_domdesc , &
Expand Down Expand Up @@ -1734,10 +1733,6 @@ SUBROUTINE dealloc_space_field ( grid )

TYPE(domain) , POINTER :: grid

! Local data.

INTEGER :: ierr

# include "deallocs.inc"

END SUBROUTINE dealloc_space_field
Expand Down
88 changes: 88 additions & 0 deletions main/depend.common
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,82 @@ module_comm_nesting_dm.o: \
module_dm_stubs.F: \
module_domain.o

# For the following dealloc_* source files, as they are generated by the registry
# we must make that a dependency. There is no actual registry target and is
# instead facilitated via the module_state_description.F recipe. Placing a dependency on
# module_state_description.F forces the registry to be run if the following source
# files are required implicitly by their respective .o recipe
../inc/deallocs_0.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_0.F : module_state_description.F


../inc/deallocs_1.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_1.F : module_state_description.F


../inc/deallocs_2.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_2.F : module_state_description.F


../inc/deallocs_3.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_3.F : module_state_description.F


../inc/deallocs_4.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_4.F : module_state_description.F


../inc/deallocs_5.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_5.F : module_state_description.F


../inc/deallocs_6.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_6.F : module_state_description.F


../inc/deallocs_7.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_7.F : module_state_description.F


../inc/deallocs_8.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_8.F : module_state_description.F


../inc/deallocs_9.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_9.F : module_state_description.F


../inc/deallocs_10.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_10.F : module_state_description.F


../inc/deallocs_11.o : \
module_wrf_error.o \
module_domain_type.o
../inc/deallocs_11.F : module_state_description.F


module_domain.o: \
module_domain_type.o \
Expand All @@ -91,6 +167,18 @@ module_domain.o: \
module_alloc_space_7.o \
module_alloc_space_8.o \
module_alloc_space_9.o \
../inc/deallocs_0.o \
../inc/deallocs_1.o \
../inc/deallocs_2.o \
../inc/deallocs_3.o \
../inc/deallocs_4.o \
../inc/deallocs_5.o \
../inc/deallocs_6.o \
../inc/deallocs_7.o \
../inc/deallocs_8.o \
../inc/deallocs_9.o \
../inc/deallocs_10.o \
../inc/deallocs_11.o \
module_driver_constants.o \
module_configure.o \
module_machine.o \
Expand Down
19 changes: 19 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ elseif ( ${WRF_CORE} STREQUAL "DA" OR ${WRF_CORE} STREQUAL "DA_4D_VAR" )

endif()

set( dealloc_source )
foreach( n RANGE 0 11 )
list(
APPEND
dealloc_source
${CMAKE_BINARY_DIR}/inc/deallocs_${n}.F
)

endforeach()

get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
wrf_expand_definitions(
RESULT_VAR REGISTRY_DEFS
Expand All @@ -112,6 +122,7 @@ add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/inc/nl_config.inc
${CMAKE_BINARY_DIR}/frame/module_state_description.F
${dealloc_source}
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}
# Replicate what exists in project directory for registry
Expand All @@ -138,5 +149,13 @@ add_custom_target(
DEPENDS
${CMAKE_BINARY_DIR}/inc/nl_config.inc
${CMAKE_BINARY_DIR}/frame/module_state_description.F
${dealloc_source}
)

target_sources(
${PROJECT_NAME}_Core
PRIVATE
${dealloc_source}
${CMAKE_BINARY_DIR}/frame/module_state_description.F
)

73 changes: 70 additions & 3 deletions tools/gen_allocs.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,30 +589,97 @@ gen_dealloc1 ( char * dirname )
FILE * fp ;
char fname[NAMELEN] ;
char * fn = "deallocs.inc" ;
// Open array of deallocs_[n].inc
int numFiles = 12;
int idx = 0;
FILE * fpSub;
char * filename_prefix = "deallocs_" ;
mgduda marked this conversation as resolved.
Show resolved Hide resolved

if ( dirname == NULL ) return(1) ;
if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
else { sprintf(fname,"%s",fn) ; }
if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
print_warning(fp,fname) ;
gen_dealloc2( fp , "grid%", &Domain ) ;

fprintf(
fp,
"INTERFACE\n"
);
if ( dirname == NULL ) return(1) ;
for ( idx = 0; idx < numFiles; idx++ )
{
if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s%d.F",dirname,filename_prefix,idx) ; }
else { sprintf(fname,"%s%d.F",dirname,filename_prefix,idx ) ; }
if ((fpSub = fopen( fname , "w" )) == NULL ) return(1) ;

print_warning(fpSub,fname) ;

fprintf(
fp,
" SUBROUTINE %s%d( grid )\n"
" USE module_wrf_error\n"
" USE module_domain_type\n"
" IMPLICIT NONE\n"
" TYPE( domain ), POINTER :: grid\n END SUBROUTINE\n",
filename_prefix, idx
);

fprintf(
fpSub,
"SUBROUTINE %s%d( grid )\n"
" USE module_wrf_error\n"
" USE module_domain_type\n"
" IMPLICIT NONE\n"
" TYPE( domain ), POINTER :: grid\n INTEGER :: ierr\n",
filename_prefix, idx
);
gen_dealloc2( fpSub, "grid%", &Domain, idx, numFiles );
fprintf(
fpSub,
"END SUBROUTINE %s%d\n",
filename_prefix, idx
);
close_the_file( fpSub ) ;
}
fprintf(
fp,
"END INTERFACE\n"
);

// Call the functions in the inc
for ( idx = 0; idx < numFiles; idx++ )
{
fprintf(
fp,
"CALL %s%d( grid )\n", filename_prefix, idx
);
}
close_the_file( fp ) ;
return(0) ;
}

int
gen_dealloc2 ( FILE * fp , char * structname , node_t * node )
gen_dealloc2 ( FILE * fp , char * structname , node_t * node, int idx, int numFiles )
{
node_t * p ;
int tag ;
char post[NAMELEN] ;
char fname[NAMELEN] ;
char x[NAMELEN] ;
int currentIdx = -1;

if ( node == NULL ) return(1) ;

for ( p = node->fields ; p != NULL ; p = p->next )
{
// Modulo to divert each field based on index to a file
// Skip if this field is not part of that index and idx != -1, so -1 can be used to force output
currentIdx = ( currentIdx + 1 ) % numFiles;
if ( currentIdx != idx && idx != -1 )
{
continue;
}

if ( (p->ndims > 0 || p->boundary_array) && ( /* any array or a boundary array and... */
(p->node_kind & FIELD) || /* scalar arrays or */
(p->node_kind & FOURD) ) /* scalar arrays or */
Expand Down Expand Up @@ -682,7 +749,7 @@ structname, fname, structname, fname ) ;
else if ( p->type->type_type == DERIVED )
{
sprintf(x,"%s%s%%",structname,p->name ) ;
gen_dealloc2(fp,x, p->type) ;
gen_dealloc2(fp,x, p->type, idx, -1) ;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int gen_ddt_write ( char * );
int gen_ddt_write1 ( FILE *, char *, node_t *);
int gen_dealloc ( char * );
int gen_dealloc1 ( char * );
int gen_dealloc2 ( FILE *, char *, node_t *);
int gen_dealloc2 ( FILE *, char *, node_t *, int idx, int numFiles );
int gen_scalar_tables ( FILE *);
int AppendReg ( char *,int);
int irr_diag_scalar_indices ( char * );
Expand Down
12 changes: 12 additions & 0 deletions var/build/da.make
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ WRFVAR_OBJS = \
module_alloc_space_7.o \
module_alloc_space_8.o \
module_alloc_space_9.o \
inc/deallocs_0.o \
inc/deallocs_1.o \
inc/deallocs_2.o \
inc/deallocs_3.o \
inc/deallocs_4.o \
inc/deallocs_5.o \
inc/deallocs_6.o \
inc/deallocs_7.o \
inc/deallocs_8.o \
inc/deallocs_9.o \
inc/deallocs_10.o \
inc/deallocs_11.o \
nl_get_0_routines.o \
nl_get_1_routines.o \
nl_get_2_routines.o \
Expand Down
1 change: 1 addition & 0 deletions var/build/da_name_space.pl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
med_restart_out
med_latbound_in
module_alloc_space
deallocs_
module_configure
module_scalar_tables
module_nesting
Expand Down
Loading