Loading...
You are not logged-in Login/Register





  • Posts   Search Threads
  • Debanjan MukherjeeOctober 28, 2011 11:11 AM PDT   
    Derived data types with allocatable components

    Hello,

    I think I have some flaws in my understanding of the derived data types and how the memory allocation happens for them. I am currently working on a problem where I have to create some form of a list with variable number of entries, and I am trying to create a data type for that using allocatable components as follows:

    type boxList
    integer, dimension(:), allocatable:: boxTuples
    integer, dimension(:), allocatable:: boxMembers
    end type boxList

    type(boxList), dimension(:),allocatable:: myboxList

    1. One of the reasons why I wanted to have the components allocatable - is because I was intending on  performing something like a 'push_back()' operation in C++ on my vector boxMembers to keep adding entries. But that leavse me with an allocatable array of derived types with allocatable components - and I am not sure how the memory assignment works here.

    2. Could I first allocate the array myboxList
    and then for each list - I go in and allocate the individual members ?

    3. Also, is there any way in which I can define a constant number at runtime - something like ./executible.out "constant-number"
    like we can do with c++ codes ? I ask this because if so, then I can fix the dimension of one of the member vectors by writing for example ./executible.out 3 for a 3 dimensional problem - (effectively for my physics simulator, this is the number of space dimensions I am working with). I guess this would be the equivalent of main(int argc) or something.

    Any pointers will be very helpful to aid my understanding of these derived types.
    Thank you.

    Steve Lionel (Intel)October 28, 2011 12:58 PM PDT
    Rate
     
    Derived data types with allocatable components

    When you have an array of derived types with allocatable components, yes you need to allocate the parent array first and then allocate the components.  I am not familiar with push_back in C++.  I will note that you can simply assign to allocatable arrays and have the allocation happen automatically if you add -standard-semantics.

    I don't know how you do what you're discussing in C++ - it sounds to me as if you have something that reads the argument list.  This is hardly a "constant".  But you can obtain a value from the argument list (as a string) using GET_COMMAND_ARGUMENT and then decode it as you wish, then use the value in an ALLOCATE statement.

    Steve

    Attaching or including files in a post
    Doctor Fortran blog
    @DoctorFortran on Twitter

Forum jump:  

Intel Software Network Forums Statistics

17,025 users have contributed to 48,319 threads and 172,758 posts to date.

In the past 24 hours, we have 11 new thread(s) 54 new posts(s), and 47 new user(s).

In the past 3 days, the most popular thread for everyone has been Optimalization of sine function\'s taylor expansion The most posts were made to Most likely, the issue is that The post with the most views is Optimalization of sine function\'s taylor expansion

Please welcome our newest member redfruit83


For more complete information about compiler optimizations, see our Optimization Notice.