next up previous contents index
Next: Limitations With Using Shared Up: FIT2D as a Sub-Process Previous: Using FIT2D in ``Command-line''

Using FIT2D with Shared Memory

(Note: At present this only works with the Linux version of FIT2D although a Windows enabled version is forseen.)

Note: This section is only for knowledgeable software engineers, casual FIT2D users should not attempt to work with shared memory, unless they have a good understanding of the concepts involved and have a reasonable understanding of ``ANSI-C'' and the Linux operating system, and / or the Windows operating system.)

If FIT2D is used as a sub-process it can be important to be able to pass data to and from FIT2D quickly and efficiency. The most efficient manner is to use ``shared memory''. Shared memory means that both processes can acces the same array of memory. In FIT2D the memory is used for the program arrays. Thus, FIT2D could be used to input data using one of the many file format input choices, the data could then be manipulated by the calling program, and finally output using one of FIT2D's output formats.

To use FIT2D with shared memory a utility routine f2d_sharedsizec is available to calculate the number of bytes necessary to allocate.

e.g. If xdim has been set the the number of pixels in the X-direction, and ydim to the number of pixels in the Y-direction, and memory arrays are required, but not variance arrays, the following call would be used to calculate the number of bytes to allocate:

  /* Calculate size of shared memory segment */
  num_bytes = f2d_sharedsizec (xdim, ydim, TRUE, FALSE);

(f2d_sharedsizec is shown in full, and further explanation is given in Section 24.4, Page [*]). When a shared memory segment is created and allocated, the ``identifier'' of the shared memory segment needs to be passed to FIT2D so that FIT2D can use the same memory space. This is done using the -id= (or +id=, -ID=, +ID=) command-line option. e.g. If FIT2D is to be used with a shared memory segment whose identifier is 123456 the following code could be used to start up FIT2D using shared memory:

  /* Open FIT2D as a sub-process with input through a pipe, and using a
     shared memory segment */
  command = (FILE *) popen ("/usr/local/bin/fit2d -com -id=123456", "w");

When the main program array is filled by the calling process, it is necessary to tell FIT2D that the main program array contains data (otherwise, it refuses to display or do operations on it). This can be achieved using the -data (or +data, -DATA, +DATA) command-line option.

The following example call, copies the previous example, but this time tells FIT2D that the main program array has been defined:

  /* Open FIT2D as a sub-process with input through a pipe, and using a
     shared memory segment, with data defined by the calling program. */
  command = (FILE *) popen ("/usr/local/bin/fit2d -com -data -id=123456", "w");

The memory allocated including space for the main program array, a mask array, axis arrays, and optionally for variance arrays, and memory arrays. The code in Section 24.5, Page [*] shows an example of calculating and setting these addresses. This can be adapted for your own purposes.

(On Linux systems man shmget and man shmat provides documentation on using shared memory. General use of shared memory is outside the scope of this manual.)


next up previous contents index
Next: Limitations With Using Shared Up: FIT2D as a Sub-Process Previous: Using FIT2D in ``Command-line''
Andrew Hammersley
2004-01-09