Operating System - OpenVMS
Showing results for 
Search instead for 
Did you mean: 

Mapping to global sections with FORTRAN and C

Jon Pinkley
Honored Contributor

Re: Mapping to global sections with FORTRAN and C


Hoff's code is an example program that isn't meant to do anything useful. The purpose is to show how to get the syntax correct for people that are having problems with the basics.

Global sections are used to allow multiple processes to access the same physical memory, in ether read-only mode or read write mode.

An example of what VMS uses global sections for are for programs that are installed /shared. This allows multiple processes to share the physical memory that is holding the code (read only) portion of the program. See $ help install add /shared

There are very few times I would recommend end users using global sections. The o/s needed them, the work was already done, and when VMS was written, memory was EXPENSIVE and in general the programmers were much more interested in the nitty-gritty details of the O/S. Many programmed in VAX assembly language. The source code for VMS was even shipped to customers on micro fiche. So the APIs were documented, and people were able to use them as well as the operating system.

Having shared writable memory and maintaining correct synchronization to it is not trivial. As others have said, RMS indexed files with global buffers work quite well and the hard work has already been done and debugged.

The HP OpenVMS Programming Concepts Manual is the place to start if you want some basic info.

http://h71000.www7.hp.com/doc/os83_index.html (index of O/S documentation)

HTML version of manual


PDF (two parts)

http://h71000.www7.hp.com/doc/82FINAL/5841/aa-rnshd-te.PDF (part 1)

http://h71000.www7.hp.com/doc/82final/5841/aa-pv67h-tk.PDF (part 2)

This stolen directly from chapter 3 of HP OpenVMS Programming Concepts Manual:

"Global sections: Global sections can be either disk files or page-file sections that contain shareable code or data. Through the use of memory management services, these files can be mapped to the virtual address space of more than one process. In the case of a data file on disk, cooperating processes can synchronize reading and writing the data in physical memory; as data is updated, system paging results in the updated data being written directly back into the disk file. Global page-file sections are useful for temporary storage of common data; they are not mapped to a disk file. Instead, they page only to the system default page file. Global sections are described in more detail in Chapter 13 and Chapter 12."

it depends
Honored Contributor

Re: Mapping to global sections with FORTRAN and C

Cynical view follows:

Global sections and shared memory and Fortran COMMON structures are used by various ancient or misguided folks and rarely by a few and skilled folks as an approach to share application data in memory, and sometimes in the usually false belief that the use of these shared memory structures will provide performance benefits over more modern designs as compared with the maintenance and support overhead.

These older models and structures are also used by those looking to sabotage a software project schedule or the software product stability, or to seek a form of perpetual employment.

Locally-written shared memory solutions often to provide a means to inject obscure and application-destabilizing and subtle run-time errors. This with matters of processor caching and proper memory synchronization. And a means to introduce limits to application scaling, too.

Better approaches include databases and RMS files with global buffers enabled. They're also more portable.

If you're working for me and you use a shared global section, you're going to expect be in my office having a design discussion; you're going to need justification for using what is usually budget- or schedule-busting programming "solution." Can this sharing design be implemented successfully? Sure. Are you willing to read and heed the architecture- and processor-level manuals for each box you're working with? There are alternatives here, and often vastly superior better alternatives. And the best part: alternatives that deal with the caching and careful writes and updates and such that somebody else is going to maintain and upgrade, too.

There are "libraries" around that allow you to share data far more effectively.

John Gillings
Honored Contributor

Re: Mapping to global sections with FORTRAN and C

Having successfully implemented systems that use shared memory data structures, I can confirm most of what Hoff says. You can get a performance advantage, BUT only when there is some kind of specific property in your data that can be exploited. If you're not sacrificing generality to gain performance, you're re-implementing RMS and you won't win!

That said, the key to writing code that is solid and dependable is to package your shared data structure in a procedural interface that makes sense at application level. It should not reveal any detail of the lower level implementation. By forcing all accesses through a common interface, you can enforce synchronisation, and change internal details when and if necessary.

Start by instantiating the interface using the simplest mechanism. Most likely RMS. Once you have the application working, implement the same mechanism using (say) global sections and locks. This should not require any changes at application level. All you're doing is replacing the RMS implementation. If this is done correctly, it will be possible to plug in other mechanisms, like networked client/server, or move your portable application level code to other architectures or operating environments.

If you're exposing and directly accessing the "naked" data structures directly in your application code, you're doomed to failure.
A crucible of informative mistakes
Honored Contributor

Re: Mapping to global sections with FORTRAN and C

What John G. is referring to in his reply is known as Model View Controller (MVC) on other platforms.

Or as "premature optimization", depending on the particular antecedent.
Robert Gezelter
Honored Contributor

Re: Mapping to global sections with FORTRAN and C


I agree with Hoff and John.

Quite a while ago, a client "asked" me to use shared global sections to achieve "efficiency". For a variety of reasons, most of which had to do with integrity in the face of software component malfunction and time to completion, I used DECnet Task-to-Task logical links to implement what is now generally referred to as MVC.

Despite management concerns, the performance of the system was never a problem, even on processors far slower than todays (first generation Alphas), and at transaction volumes orders of magnitude larger than ever occurred.

The resulting product was also so stable that it was used for production as a Beta.

A good object lesson.

- Bob Gezelter, http://www.rlgsc.com
Hein van den Heuvel
Honored Contributor

Re: Mapping to global sections with FORTRAN and C

Shared global sections are often used for message passing. Very nice, when done right, but as pointed out, a well designed RMS solution may be plenty fast. And maybe you can use a tool like SYS$ICC which has done the dirty work for you (John may dissagree :^).

That said, shared global sections are great for certain easy task where even a poor implementation is good enough. Like a 'shut down flag'. A data lookup table, or a 'please-re-read config file flag. Or perhaps application throughput and usage counters where a dirty write is acceptable. Yes 'locks' and ast's may be better for some of those, Logical name have been used, but a shared global section has its place. Such lookup table can be protected with a single simple CR lock, where an RMS indexed file would typically involve much more locking unless very careful (GBC, NQL, MSE,..)


Honored Contributor

Re: Mapping to global sections with FORTRAN and C

> Yes 'locks' and ast's may be better for some of those, ....

Or for basic process states and for flags-oriented stuff, a common event flag cluster and event flags can be used; the sys$ascefc system service call and related routines.

John Gillings
Honored Contributor

Re: Mapping to global sections with FORTRAN and C

>And maybe you can use a tool like SYS$ICC
>which has done the dirty work for you (John
>may dissagree :^).

Now that OpenVMS engineering has fixed all the bugs I know of in ICC, I won't disagree! ICC is a magic mechanism. Cluster transparent and very fast. However, if you use it, make sure you have all the latest patches (including the ones which should hit ITRC in a couple of weeks...)

A crucible of informative mistakes
Scot Newton

Re: Mapping to global sections with FORTRAN and C

Thanks to all for the assistance. Apologies for closing the thread so late!