Calculating the sizes of data structures

As mentioned above, the shared memory region is divided into two sections, each beginning on a 4k page boundary. The first section contains the adios_signature_t, followed by the adios_daq_status_t, followed by one adios_cis_t for each installed card.

Suppose that we have one PCL-711 card and one DIO-144 installed. This is what the first part of the memory layout will look like:

Layout of first and second data segment Figure 1. ADIOS shared memory.

The second part of the shared memory contains the data. Each data set consists of a tiny adios_data_header_t followed by the samples from the various cards. There are as many data sets as specified with the command line -S option (or the default of 1000).

Continuing with our example of the two cards from above, here's what the first and part of the second data set look like:

First and second part of data set Figure 2. Two sets of samples in shared memory.

Therefore, the first job of create_shmem() is to figure out the sizes of the various data structures.

create_shmem (void)
  int   size;
  int   size_c, size_d;
  int   size_d_ai, size_d_di;
  int   size_element;
  int   i;
  int   sts;

  // size_c is the control section size
  size_c = sizeof (adios_signature_t) + sizeof (adios_cis_t) * nadios;

  // size_d is the data section size
  size_d = sizeof (adios_data_header_t);
  for (i = 0; i < nadios; i++) {
    size_d_ai = adios [i].nai * ((adios [i].maxresai + 15) / 16) * 2;
    size_d_di = (adios [i].ndi + 31) / 32 * 4;
    size_d += size_d_ai + FILLER_ALIGN_32bits (size_d_ai) + size_d_di;
  size_element = size_d;
  size_d *= optS;

  // compute the total size of shared memory
  size = size_c + FILLER_ALIGN_4kbytes (size_c) 
       + size_d + FILLER_ALIGN_4kbytes (size_d);

As you can see, the code runs through the adios global database that it filled in as the final phase of option processing, and accumulates the total data sizes that all of the samples will need. The optS variable is the number of samples; once we know each sample's size we multiply by that number to compute the total size. The total size of the shared memory is size_c (rounded up to be a multiple of 4096 bytes) plus size_d (also rounded up).