简体   繁体   English

Fortran77代码中的动态内存分配(PNL分配器)

[英]Dynamic Memory Allocation in Fortran77 code (PNL Allocator)

I am working on an application, which is written primarily in Fortan77. 我正在开发一个主要用Fortan77编写的应用程序。 Since fortran77 does not support dynamic memory allocation, the code utilizes the PNL Dynamic Memory Allocator: http://www.emsl.pnl.gov/docs/global/ma/MAapi.html 由于fortran77不支持动态内存分配,因此该代码利用了PNL动态内存分配器: http ://www.emsl.pnl.gov/docs/global/ma/MAapi.html

However can someone provide an explanation for: 但是有人可以提供以下解释:

   int_mb(index + i)

what does int_mb and similarly dlb_mb return? int_mb和类似的dlb_mb返回什么?

If cost is an integer, what would dlb_mb(cost) specify? 如果cost是整数,那么dlb_mb(cost)指定什么?

Thank you for your time. 感谢您的时间。

However can someone provide an explanation for: int_mb(index + i) 但是有人可以提供以下解释:int_mb(index + i)

That sets (eg zeroes) allocated memory. 设置(例如零)分配的内存。

http://www.emsl.pnl.gov/docs/global/ma/MA_alloc_get.html http://www.emsl.pnl.gov/docs/global/ma/MA_alloc_get.html

#include "mafdecls.h"

      logical ok
      integer mhandle
      integer index
      integer i

      ok = MA_alloc_get(MT_INT, 5, 'heap int block', mhandle, index)
      if (ok) then
          do 10 i = 0, 4
              int_mb(index + i) = 0
10        continue
      endif

what does int_mb and similarly dlb_mb return? int_mb和类似的dlb_mb返回什么?

dbl_mb that is. dbl_mb是。

From https://svn.pnl.gov/svn/hpctools/trunk/ga/ma/mafdecls.fh.in (user: anonymous, pw: anonymous) I'd guess they return the previous value at that mem. https://svn.pnl.gov/svn/hpctools/trunk/ga/ma/mafdecls.fh.in (用户:匿名,pw:匿名)中,我猜他们会在该内存处返回先前的值。 loc.; loc .; simply try out by invoking twice in a row and assigning different values, then trace the second return val. 只需通过连续两次调用并分配不同的值来进行尝试,然后跟踪第二个返回值。

When you initialize an array using ma_alloc_get , you specify what memory type you are allocating (int = mt_int , double = mt_dbl , etc.) and it gives you back a memory handle and an index. 当使用ma_alloc_get初始化数组时,您可以指定要分配的内存类型(int = mt_int ,double = mt_dbl等),它为您提供内存句柄和索引。 The index is used to access specific values within the MA array. 该索引用于访问MA数组中的特定值。

Let's say you've allocated an array of integers and index is your index. 假设您分配了一个整数数组,而index是您的索引。 int_mb(index) would be the first element in that array. int_mb(index)将是该数组中的第一个元素。 Therefore, int_mb(index + i) would be element i+1 . 因此, int_mb(index + i)将是元素i+1

dbl_mb(cost) would be the double located at cost in the double block. dbl_mb(cost)将是double块中位于cost处的double。 a = dbl_mb(cost) would access this value while dbl_mb(cost) = 123.45 would set the value, provided that cost points to an initialized block of memory. a = dbl_mb(cost)将访问此值,而dbl_mb(cost) = 123.45将设置该值,前提是cost指向已初始化的内存块。

I personally like to think of 'mt' as 'memory type' and 'mb' as 'memory block', since that's what they are essentially doing. 我个人喜欢将“ mt”视为“内存类型”,将“ mb”视为“内存块”,因为这实际上是他们所做的。 'mt' variables are internal integers so the allocator knows which memory block to allocate to and 'mb' calls are accessing specific locations on that block. “ mt”变量是内部整数,因此分配器知道要分配给哪个内存块,并且“ mb”调用正在访问该块上的特定位置。

You can read more on their API page . 您可以在其API页面上阅读更多内容。

Use Fortran 90+ dynamic memory allocation. 使用Fortran 90+动态内存分配。 There is absolutely no reason for MA to exist anymore except as a historical artifact in NWChem. 除了作为NWChem中的历史产物之外,MA绝对没有理由再存在了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM