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





  • Posts   Search Threads
  • hamid3252January 31, 2012 11:17 PM PST   
    How to define a dynamic array which is global (common)

    Hi,
    I have defined a dynamic array like this: 
          integer, dimension(:), allocatable::nCommonIndex
    But still could not figure out how I can make it a global variable. I tried this syntax just after the decleration:
          common /nCommon/ nCommonGrainIndex
    But it gives me the error saying: 
    error #6406: Conflicting attributes or multiple declaration of name.   [NCOMMONGRAININDEX]
          common /nCommon/ nCommonGrainIndex
            -----------------------^
    Appreciate if you can help me with this issue.
    Thanks,
    HR.


    arjenmarkusJanuary 31, 2012 11:22 PM PST
    Rate
     
    How to define a dynamic array which is global (common)

    You should be aware that Fortran does not have truly global variables. You can share
    variables by COMMON blocks (the ancient way that you should avoid) and modules.

    Try:

    module commons
         integer, dimension(:), allocatable :: nCommonIndex
    end module commons

    And wherever you need this array:

    subroutine needToUseCommons
          use commons ! The name of the module

          ...
          allocate( nCommonIndex(10) )  ! Allocate it for further use
          ...
    end subroutine needToUSeCommons


    Regards,

    Arjen

    hamid3252January 31, 2012 11:46 PM PST
    Rate
     
    How to define a dynamic array which is global (common)

    Thanks Arjen! But what I really need is a shared memory (an array with dynamic size), similar to a singleton pattern we can define in JAVA or C++ through "static" decleration. One of my subroutines can be invoked by multiple threads and this is an array I am sharing among them. I doubt that the module-methodology you suggest (which are essencially classes in new Fortran) acts the same way, whereas a COMMON block (though deprecated) does it well. Am I missing something? 
    Rgds,
    HR


    arjenmarkusJanuary 31, 2012 11:51 PM PST
    Rate
     
    How to define a dynamic array which is global (common)

    No, a module variable is a singleton, to use "patternspeak". There can be only one copy in the
    entire program. In that way it behaves as a COMMON block - but from the point of view of
    robustness and maintainability, it is much more convenient than COMMON blocks as you
    define it in one single place and use it anywhere via the USE statement without any chance
    of not exactly using the same declarations, as can happen with COMMON blocks.

    Regards,

    Arjen

    hamid3252January 31, 2012 11:56 PM PST
    Rate
     
    How to define a dynamic array which is global (common)

    Thanks! Let me modify my code and try it.

    hamid3252February 1, 2012 2:22 AM PST
    Rate
     
    How to define a dynamic array which is global (common)

    I created a file (commonVars.f90) and defined a module like this:
     
    module commonVarsModule
      CHARACTER::command*200
    module commonVarsModule
    in another file, I have a subroutine using this module as: 
      
    subroutine testSub()
    !{
      !IMPLICIT double precision (A-H,O-Z)
      use commonVarsModule
      implicit none
      
      command = ""
    !}
    end subroutine testSub
    It is compiled well, but I am getting linker error. Sounds like no where any reference is defined by the fortran compiler.
     
    Umat-Main-Mgr-Test-0032.obj : error LNK2019: unresolved external symbol COMMONVARSMODULE_mp_COMMAND referenced in function TESTSUB
     
    Do I need to define a variable of this type (module) somewhere esplicitly? 
     
    Thanks,
    HR.


    mecej4February 1, 2012 2:39 AM PST
    Rate
     
    How to define a dynamic array which is global (common)

    When you compile the file containing the module, a .MOD file and a .OBJ file are produced. At link time, you should include the .OBJ file in the command line to avoid the "unresolved external symbol" message for the module-level variables.

    hamid3252February 1, 2012 3:20 AM PST
    Rate
     
    How to define a dynamic array which is global (common)

    Thanks. I included both F90 files after ifort command line and it compiled and linked them together.

    hamid3252February 1, 2012 5:15 PM PST
    Rate
     
    How to define a dynamic array which is global (common)

    May I ask one more question? I would like to statically link the obj files into a single obj file as I need to finally have only a single (stand-alone) obj file. I know I can concatenate them using "Lib" command, but then I miss the debug-information file (*.pdb) which are creadted along with the obj files in full debug mode. I am using pdb file to debug my code by attaching the runing process to VS2008 debugger. Is it any way to go around this problem? 
     
    Thanks,
    HR.


    Steve Lionel (Intel)February 2, 2012 5:39 AM PST
    Rate
     
    How to define a dynamic array which is global (common)

    I'm pretty sure that when you build a static library project that all the PDB information gets merged into one PDB file.  This would be better than a single .obj.

    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,321 threads and 172,753 posts to date.

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

In the past 3 days, the most popular thread for everyone has been How to manage rounding by IVF ?? 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.