Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Shared Memory Question

Intel_C_Intel
Employee
715 Views
I've inherited some shared memory code that I'm trying to update. I have the following in a module:
INTEGER*4a_shared_item(CLASS_REC_SIZE * MAX_SHARE) POINTER(p_dy_item, a_shared_item)
INTEGER*4a_shared_stream(FLUID_REC_SIZE * MAX_SHARE) POINTER(p_dy_stream, a_shared_stream)
INTEGER*4a_shared_item_key(KEY_SIZE * MAX_SHARE) POINTER(p_dy_item_key, a_shared_item_key)
INTEGER*4a_shared_stream_key(KEY_SIZE * MAX_SHARE) POINTER(p_dy_stream_key, a_shared_stream_key)

At present, a file/file mapping is created for each of these arrays, which I find a little messy (why use four files?). Could I put these arrays in a TYPE and still have pointers to each array? Or am I asking for trouble?

Dan

0 Kudos
7 Replies
Jugoslav_Dujic
Valued Contributor II
715 Views

Yes, you can put them in a TYPE and have a pointer only to a TYPE -- the references will be automagically resolved once you get a pointer to the type so that you can refer to them as T%a_shared_item, etc.

If you prefer not to refer to them as T%a_shared_item, you can have that too -- just define a pointers as you have now but do not dereference them using shared memory but rather as:

p_dy_item = LOC(T%a_shared_item)
a_shared_item(1)= something
!same asT%a_shared_item(1) = something

This will work only if the arrays are normal, static components of T -- not if they're POINTERs or ALLOCATABLEs.

Jugoslav

0 Kudos
Steven_L_Intel1
Employee
715 Views
Just be aware that the "Cray POINTER" extension you're using doesn't work inside derived types. You may be able to use standard Fortran pointers instead, but that depends on your application.
0 Kudos
Intel_C_Intel
Employee
715 Views
Steve - but I can still use a CRAY pointer to point at the whole TYPE, is that correct? (as Jugoslav intimated...)
0 Kudos
Jugoslav_Dujic
Valued Contributor II
715 Views

Certainly. I do it all the time. (If you're familiar with Win32, take a look e.g. at NMHDR argument of WM_NOTIFY message).

Jugoslav

0 Kudos
Intel_C_Intel
Employee
715 Views

OK...I got it going with a TYPE, which is great. But I notice my process is now leaking handles when I run the memory sharing model. Obviously I need to CLOSEHANDLE my file handles, but what about UnMapViewOfFile? Presumably that needs to be called after the data is read/written? (You can probably tell I'm kinda making this up as I go along...!)

0 Kudos
Jugoslav_Dujic
Valued Contributor II
715 Views

Quote from remarks section of CreateFileMapping entry:

To fully close a file-mapping object, an application must unmap all mapped views of the file-mapping object by calling UnmapViewOfFile, and close the file-mapping object handle by calling CloseHandle. The order in which these functions are called does not matter. The call to UnmapViewOfFile is necessary because mapped views of a file-mapping object maintain internal open handles to the object, and a file-mapping object will not close until all open handles to it are closed.

Jugoslav
0 Kudos
Intel_C_Intel
Employee
715 Views

Ok...thanks Jugoslav...I stuck in some CLOSEHANDLEs and an UNMAPVIEWOFFILE and my handle leak appears to have gone away!

0 Kudos
Reply