Share Type

Next: , Previous: Multiple, Index: Index

This share[variablename] (where variablename is a variable name) allows the programmer to have two variables sharing the same memory (the variable that the share type is applied to uses the memory of that specified as arguments to the type.) This is very useful in HPC applications as often processes are running at the limit of their resources. It also allows for the programmer to take a completely different view of some data - remember previously we said that during execution the allocation type of a variable may not change, well using this share type is a way to get around this if required.

  • Error Checking - The memory allocated to the variable appearing in the share type must be greater than or equal to the memory requirements of the variable the type is acting upon.
  • Dynamic Checking - Although bounds can often be checked statically, if the element type changes (i.e. from an integer to character) then a check will be performed dynamically as the size of these types is implementation specific to C.

    Examples

    var a:Int::allocated[multiple[]];
    var c:Int::allocated[multiple[] :: share[a]];
    var e:array[Int,10]::allocated[single[on[1]]];
    var u:array[Char,12]::allocated[single[on[1]] :: share[e]];

    In the example above, firstly the variables a and c will share the same data. Secondly, the variables e and u will also share the same data. There is some potential concern that this might result in an error - as the size of u array is 12, and size of e array is only 10. Seeing the two arrays have different types then this size will be checked dynamically - as an int in C is usually 32 bit and a char usually only 8 then most likely this sharing of data would actually work in this case.

    Last Modified: August 2008