| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi! I have an allocation problem: my memory is too small for my variables. To solve this I seek help! Background: an atmospheric dispersion model that makes concentration maps of a set of dispersed substances. I have a module that supports variables of type SubstanceVector, an array with a fixed length: MaxNSubstances = 242 TYPE SubstanceVector REAL(Float), DIMENSION(MaxNSubstances) :: Values END TYPE SubstanceVector There is a database providing all characteristics for the 242 substances. The module contains operators, functions etcetera for all sorts of transformations and reactions of the substances. In practice, a regular problem uses about 30 different substances, but you never know which ones on beforehand. Based on the input parameters, the first step in my program is to find out the final subset of substances for this problem. Another module supports maps. To get a map of the relevant substances, there is a user-defined type: TYPE SampleGridType ....... TYPE(SubstanceVector), DIMENSION(:,:, , ALLOCATABLE ::Concentration ....... END TYPE SampleGridType With 242 substances and a map of 151 * 91 grid nodes for concentrations at 5 vertical levels, the space to be allocated for just the concentration component becomes about 67 MB when 4-byte reals are used. My pc has just 504 MB and "concentration" is not the only component of SampleGridType. To reduce memory needed for allocation, I would like to be able to set the value of MaxNSubstances at runtime once I know which subset will be used. Or have the "Values" component of SubstanceVector allocatable. But then an attempt to allocate space for SampleGridType %Concentration will fail. I could glue the two datatypes together and have something like TYPE SampleGridType REAL(Float), DIMENSION(:,:,:, , ALLOCATABLE :: ConcentrationEND TYPE SampleGridType where the first and fastest running index now refers to the number of the substance. Now all my nice operators and functions from the substance module are useless, since SubstanceVector does not make sense anymore. --> Which combination of user-defined types, alternative to the above SubstanceVector and SampleGridType, will facilitate the construction of maps of a VARIABLE collection of substances? Regards, Arjan |
|
#2
| |||
| |||
| Arjan <arjan.van.dijk@rivm.nl> wrote: > TYPE SubstanceVector > REAL(Float), DIMENSION(MaxNSubstances) :: Values > END TYPE SubstanceVector .... > TYPE SampleGridType > ...... > TYPE(SubstanceVector), DIMENSION(:,:, , ALLOCATABLE ::> Concentration > ...... > END TYPE SampleGridType .... > To reduce memory needed for allocation, I would like to be able to set > the value of MaxNSubstances at runtime once I know which subset will > be used. Or have the "Values" component of SubstanceVector > allocatable. But then an attempt to allocate space for SampleGridType > %Concentration will fail. I don't see why... other than that you have to allocate an object instead of a type, but that has little to do with anything you mentioned, so I assume that is just a slip of the keyboard... or maybe not. When you say that the allocation "will fail" do you mean that you actually tried it and it failed, or that you think it would fail? If you actually tried it and it failed, I'd like to see the exact code and error message. If you just think it will fail, I think you are wrong. You will have to make values allocatable, as you imply. The only thing worthy of note here is that, if samplegrid is a variable of type samplegridtype, you will need to allocate each samplegrid%concentration(i)%values to the desired size. You do have to allocate separately for each i, because each i has a separate allocatable component. So just do it in a loop. If you are trying to do it in a single allocation, that might be your problem. Otherwise, I think you'll have to show exactly what this you are doing that is failing, as it isn't evident from the description. -- Richard Maine | Good judgement comes from experience; email: last name at domain . net | experience comes from bad judgement. domain: summertriangle | -- Mark Twain |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.