From 44364dde5711aad4afe9845b547a65f5d4f25c3d Mon Sep 17 00:00:00 2001 From: Andrew Benson Date: Tue, 17 Aug 2021 14:55:25 -0700 Subject: [PATCH] fix(build): Allow build to succeed with meta-properties and GALACTICUS_ACTIVE_COMPONENTS When GALACTICUS_ACTIVE_COMPONENTS is used to specify a list of active components in the build this previously broke the build due to incompatibility with the recently-added meta-property functionality. This patch fixes that issue. --- .../Build/Components/Classes/CreateDestroy.pm | 4 +- .../Build/Components/Classes/Evolve.pm | 26 ++++++---- .../Implementations/CreateDestroy.pm | 8 +++- .../Components/Implementations/ODESolver.pm | 48 +++++++++---------- .../Implementations/Serialization.pm | 16 +++++-- 5 files changed, 61 insertions(+), 41 deletions(-) diff --git a/perl/Galacticus/Build/Components/Classes/CreateDestroy.pm b/perl/Galacticus/Build/Components/Classes/CreateDestroy.pm index 01390a5ca4..0ac393bf87 100644 --- a/perl/Galacticus/Build/Components/Classes/CreateDestroy.pm +++ b/perl/Galacticus/Build/Components/Classes/CreateDestroy.pm @@ -271,7 +271,8 @@ sub Class_Add_Meta_Property { } ] }; - $function->{'content'} = fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $function->{'content'} = fill_in_string(<<'CODE', PACKAGE => 'code'); !$GLC attributes unused :: self !$omp critical ({class->{'name'}}MetaPropertyUpdate) @@ -317,6 +318,7 @@ if (.not.found) then end if !$omp end critical ({class->{'name'}}MetaPropertyUpdate) CODE + } # Insert a type-binding for this function. push( @{$build->{'types'}->{"nodeComponent".ucfirst($code::class->{'name'})}->{'boundFunctions'}}, diff --git a/perl/Galacticus/Build/Components/Classes/Evolve.pm b/perl/Galacticus/Build/Components/Classes/Evolve.pm index 98bb93e16c..7919d601ee 100644 --- a/perl/Galacticus/Build/Components/Classes/Evolve.pm +++ b/perl/Galacticus/Build/Components/Classes/Evolve.pm @@ -73,13 +73,14 @@ sub Build_Rate_Functions { ] }; # Build the function. - $function->{'content'} = fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $function->{'content'} = fill_in_string(<<'CODE', PACKAGE => 'code'); !$GLC attributes unused :: interrupt, interruptProcedure, self CODE - $code::offsetNameAll = &offsetName('all' ,$class->{'name'},'metaProperties'); - $code::offsetNameActive = &offsetName('active' ,$class->{'name'},'metaProperties'); - $code::offsetNameInactive = &offsetName('inactive',$class->{'name'},'metaProperties'); - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + $code::offsetNameAll = &offsetName('all' ,$class->{'name'},'metaProperties'); + $code::offsetNameActive = &offsetName('active' ,$class->{'name'},'metaProperties'); + $code::offsetNameInactive = &offsetName('inactive',$class->{'name'},'metaProperties'); + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (rateComputeState == propertyTypeAll ) then offset={$offsetNameAll}(metaPropertyID) else if (rateComputeState == propertyTypeActive ) then @@ -93,6 +94,7 @@ else end if nodeRates(offset)=nodeRates(offset)+setValue CODE + } # Insert a type-binding for this function into the relevant type. push( @{$build->{'types'}->{$classTypeName}->{'boundFunctions'}}, @@ -101,7 +103,7 @@ CODE descriptor => $function, name => "metaPropertyRate" } - ); + ); } sub Build_Scale_Functions { @@ -136,11 +138,13 @@ sub Build_Scale_Functions { ] }; # Build the function. - $code::offsetName = &offsetName('all',$class->{'name'},'metaProperties'); - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $code::offsetName = &offsetName('all',$class->{'name'},'metaProperties'); + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); !$GLC attributes unused :: self nodeScales({$offsetName}(metaPropertyID))=setValue CODE + } # Insert a type-binding for this function into the relevant type. push( @{$build->{'types'}->{$classTypeName}->{'boundFunctions'}}, @@ -179,11 +183,13 @@ sub Build_Inactive_Functions { ] }; # Build the function. - $code::offsetName = &offsetName('all',$class->{'name'},'metaProperties'); - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $code::offsetName = &offsetName('all',$class->{'name'},'metaProperties'); + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); !$GLC attributes unused :: self nodeInactives({$offsetName}(metaPropertyID))=.true. CODE + } # Insert a type-binding for this function into the relevant type. push( @{$build->{'types'}->{$classTypeName}->{'boundFunctions'}}, diff --git a/perl/Galacticus/Build/Components/Implementations/CreateDestroy.pm b/perl/Galacticus/Build/Components/Implementations/CreateDestroy.pm index a22b327ee9..53d148326d 100644 --- a/perl/Galacticus/Build/Components/Implementations/CreateDestroy.pm +++ b/perl/Galacticus/Build/Components/Implementations/CreateDestroy.pm @@ -154,12 +154,14 @@ CODE } } # Allocate and initialize meta-properties. - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (allocated({$class->{'name'}}MetaPropertyNames).and..not.allocated(self%metaProperties)) then allocate(self%metaProperties(size({$class->{'name'}}MetaPropertyNames))) self%metaProperties=0.0d0 end if CODE + } # Add required modules to function. push(@{$function->{'modules'}},keys(%modules)) if ( %modules ); @@ -398,7 +400,8 @@ CODE CODE } # Build any meta-properties. - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (allocated({$class->{'name'}}MetaPropertyNames)) then !$omp critical (FoX_DOM_Access) do i=1,size(({$class->{'name'}}MetaPropertyNames)) @@ -412,6 +415,7 @@ if (allocated({$class->{'name'}}MetaPropertyNames)) then !$omp end critical (FoX_DOM_Access) end if CODE + } # Insert a type-binding for this function. push( @{$build->{'types'}->{$code::implementationTypeName}->{'boundFunctions'}}, diff --git a/perl/Galacticus/Build/Components/Implementations/ODESolver.pm b/perl/Galacticus/Build/Components/Implementations/ODESolver.pm index 931f0a38bd..bb8afff860 100644 --- a/perl/Galacticus/Build/Components/Implementations/ODESolver.pm +++ b/perl/Galacticus/Build/Components/Implementations/ODESolver.pm @@ -112,7 +112,7 @@ CODE name=self%nodeComponent{ucfirst($member->{'extends'}->{'class'}).ucfirst($member->{'extends'}->{'name'})}%nameFromIndex(count,propertyType) if (count <= 0) return CODE - } else { + } elsif ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { # Include meta-properties here. $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (allocated({$class->{'name'}}MetaPropertyNames)) then @@ -251,8 +251,8 @@ CODE $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); {$implementationTypeName}SerializeCount=self%nodeComponent{ucfirst($member->{'extends'}->{'class'}).ucfirst($member->{'extends'}->{'name'})}%serializeCount(propertyType) CODE - } else { - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + } elsif ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); {$implementationTypeName}SerializeCount={$class->{'name'}}MetaPropertyEvolvableCount CODE } @@ -389,7 +389,7 @@ if (count > 0) then offset=offset+count end if CODE - } else { + } elsif ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { # For non-extended types serialize meta-properties. $code::offsetName = &offsetName('all',$code::class->{'name'},'metaProperties'); $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); @@ -533,7 +533,7 @@ if (count > 0) then offset=offset+count end if CODE - } else { + } elsif ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { # For non-extended types serialize meta-properties. $code::offsetName = &offsetName('all',$code::class->{'name'},'metaProperties'); $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); @@ -662,7 +662,7 @@ CODE $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); call self%nodeComponent{ucfirst($code::member->{'extends'}->{'class'}).ucfirst($code::member->{'extends'}->{'name'})}%serializationOffsets(count,countSubset,propertyType) CODE - } else { + } elsif ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { # For non-extended types compute offsets for meta-properties. # Set the offset for this property to the current count plus 1 (since we haven't yet updated the count. $code::offsetNameAll = &offsetName('all' ,$code::class->{'name'},'metaProperties'); @@ -671,10 +671,9 @@ CODE $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (allocated({$class->{'name'}}MetaPropertyNames)) then CODE - - foreach my $status ( "all", "active", "inactive" ) { - $code::offsetName = &offsetName($status,$code::class->{'name'},'metaProperties'); - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + foreach my $status ( "all", "active", "inactive" ) { + $code::offsetName = &offsetName($status,$code::class->{'name'},'metaProperties'); + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (.not.allocated({$offsetName})) then allocate({$offsetName}({$class->{'name'}}MetaPropertyEvolvableCount)) else if (size({$offsetName}) /= {$class->{'name'}}MetaPropertyEvolvableCount) then @@ -682,8 +681,7 @@ CODE allocate({$offsetName}({$class->{'name'}}MetaPropertyEvolvableCount)) end if CODE - } - + } $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); do i=1,size({$class->{'name'}}MetaPropertyNames) if (.not.{$class->{'name'}}MetaPropertyEvolvable(i)) cycle @@ -761,18 +759,20 @@ sub Implementation_ODE_Offset_Variables { my $class = shift(); my $member = shift(); # Include meta-properties for just the null class (since we need only one copy of these per-class). - if ( $member->{'name'} eq "null" ) { - foreach my $status ( "all", "active", "inactive" ) { - my $offsetName = &offsetName($status,$class->{'name'},'metaProperties'); - push( - @{$build->{'variables'}}, - { - intrinsic => "integer", - ompPrivate => 1, - attributes => [ "allocatable", "dimension(:)" ], - variables => [ $offsetName ] - } - ); + if ( grep {$class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + if ( $member->{'name'} eq "null" ) { + foreach my $status ( "all", "active", "inactive" ) { + my $offsetName = &offsetName($status,$class->{'name'},'metaProperties'); + push( + @{$build->{'variables'}}, + { + intrinsic => "integer", + ompPrivate => 1, + attributes => [ "allocatable", "dimension(:)" ], + variables => [ $offsetName ] + } + ); + } } } # Iterate over non-virtual, evolving properties. diff --git a/perl/Galacticus/Build/Components/Implementations/Serialization.pm b/perl/Galacticus/Build/Components/Implementations/Serialization.pm index c0dc76c3ca..3a1bb5411d 100644 --- a/perl/Galacticus/Build/Components/Implementations/Serialization.pm +++ b/perl/Galacticus/Build/Components/Implementations/Serialization.pm @@ -142,7 +142,8 @@ CODE } } # Serialize meta-properties. - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (allocated({$class->{'name'}}MetaPropertyNames)) then do i=1,size(({$class->{'name'}}MetaPropertyNames)) write (label,{$formatLabel{'double'}}) self%metaProperties(i) @@ -151,6 +152,7 @@ if (allocated({$class->{'name'}}MetaPropertyNames)) then end do end if CODE + } $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); call displayUnindent('done') CODE @@ -264,13 +266,15 @@ CODE } } # Serialize meta-properties. - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (allocated({$class->{'name'}}MetaPropertyNames)) then do i=1,size(({$class->{'name'}}MetaPropertyNames)) write (fileHandle,'(a,a,a,{$formatLabel{'double'}},a,a,a)') ' <'//char({$class->{'name'}}MetaPropertyNames(i))//'>',self%metaProperties(i),'{'name'}}MetaPropertyNames(i))//'>' end do end if CODE + } $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); write (fileHandle,'(a)') ' {'name'}}>' CODE @@ -368,9 +372,11 @@ CODE } } # Serialize meta-properties. - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (allocated({$class->{'name'}}MetaPropertyNames)) write (fileHandle) self%metaProperties CODE + } # Insert a type-binding for this function. push( @{$build->{'types'}->{$implementationTypeName}->{'boundFunctions'}}, @@ -485,9 +491,11 @@ CODE } } # Deserialize meta-properties. - $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); + if ( grep {$code::class->{'name'} eq $_} @{$build->{'componentClassListActive'}} ) { + $function->{'content'} .= fill_in_string(<<'CODE', PACKAGE => 'code'); if (allocated({$class->{'name'}}MetaPropertyNames)) read (fileHandle) self%metaProperties CODE + } # Insert a type-binding for this function. push( @{$build->{'types'}->{$implementationTypeName}->{'boundFunctions'}},