---
name: "sc_MemoryGrp"
section: "3"
platform: "linux"
package: "libsc-doc"
version: "2.3.1-22"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/sc_MemoryGrp"
---

# sc\_MemoryGrp(3)

The MemoryGrp abstract class provides a way of accessing distributed memory in a parallel machine.

## NAME

sc::MemoryGrp - The **MemoryGrp** abstract class provides a way of accessing distributed memory in a parallel machine.

## SYNOPSIS

`#include <memory.h>`

Inherits **sc::DescribedClass**.

Inherited by **sc::MsgMemoryGrp**, and **sc::ProcMemoryGrp**.

### Public Member Functions

**MemoryGrp** (const **Ref**\< **KeyVal** \> &)\
 int **me** () const\
 Returns who I am.  int **n** () const\
 Returns how many nodes there are.  virtual void **set\_localsize** (size\_t)=0\
 Set the size of locally held memory.  size\_t **localsize** ()\
 Returns the amount of memory residing locally on **me()**.  virtual void \* **localdata** ()=0\
 Returns a pointer to the local data.  **distsize\_t** **localoffset** ()\
 Returns the global offset to this node's memory.  int **size** (int node)\
 Returns the amount of memory residing on node.  **distsize\_t** **offset** (int node)\
 Returns the global offset to node's memory.  **distsize\_t** **totalsize** ()\
 Returns the sum of all memory allocated on all nodes.  virtual void **activate** ()\
 Activate is called before the memory is to be used.  virtual void **deactivate** ()\
 Deactivate is called after the memory has been used.  virtual void \* **obtain\_writeonly** (**distsize\_t** **offset**, int **size**)=0\
 This gives write access to the memory location. No locking is done.  virtual void \* **obtain\_readwrite** (**distsize\_t** **offset**, int **size**)=0\
 Only one thread can have an unreleased obtain\_readwrite at a time.  virtual void \* **obtain\_readonly** (**distsize\_t** **offset**, int **size**)=0\
 This gives read access to the memory location. No locking is done.  virtual void **release\_readonly** (void \*data, **distsize\_t** **offset**, int **size**)=0\
 This is called when read access is no longer needed.  virtual void **release\_writeonly** (void \*data, **distsize\_t** **offset**, int **size**)=0\
 This is called when write access is no longer needed.  virtual void **release\_readwrite** (void \*data, **distsize\_t** **offset**, int **size**)=0\
 This is called when read/write access is no longer needed.  virtual void **sum\_reduction** (double \*data, **distsize\_t** doffset, int dsize)\
 virtual void **sum\_reduction\_on\_node** (double \*data, size\_t doffset, int dsize, int node=-1)\
 virtual void **sync** ()=0\
 Synchronizes all the nodes.  virtual void \* **malloc\_local** (size\_t nbyte)\
 Allocate data that will be accessed locally only.  virtual double \* **malloc\_local\_double** (size\_t ndouble)\
 virtual void **free\_local** (void \*data)\
 Free data that was allocated with malloc\_local\_double.  virtual void **free\_local\_double** (double \*data)\
 virtual void **catchup** ()\
 Processes outstanding requests.  virtual void **print** (std::ostream &o=**ExEnv::out0**()) const\
 Prints out information about the object.

### Static Public Member Functions

static **MemoryGrp** \* **initial\_memorygrp** (int &argc, char \*\*argv)\
 Create a memory group.  static **MemoryGrp** \* **initial\_memorygrp** ()\
 static void **set\_default\_memorygrp** (const **Ref**\< **MemoryGrp** \> &)\
 The default memory group contains the primary memory group to be used by an application.  static **MemoryGrp** \* **get\_default\_memorygrp** ()\
 Returns the default memory group.

### Protected Member Functions

void **obtain\_local\_lock** (size\_t start, size\_t fence)\
 void **release\_local\_lock** (size\_t start, size\_t fence)\

### Protected Attributes

int **me\_**\
 int **n\_**\
 **distsize\_t** \* **offsets\_**\
 int **debug\_**\

## Detailed Description

The **MemoryGrp** abstract class provides a way of accessing distributed memory in a parallel machine.

Several specializations are available. For one processor, **ProcMemoryGrp** provides a simple stub implementation. Parallel specializations include **ShmMemoryGrp**, **MTMPIMemoryGrp**, and **ARMCIMemoryGrp**. The particular specializations that work depend highly on the target hardware and software environment.

## Member Function Documentation

### virtual void sc::MemoryGrp::activate ()` [virtual]`

Activate is called before the memory is to be used.

Reimplemented in **sc::MTMPIMemoryGrp**.

### virtual void sc::MemoryGrp::catchup ()` [virtual]`

Processes outstanding requests. Some memory group implementations don't have access to real shared memory or even active messages. Instead, requests are processed whenever certain memory group routines are called. This can cause large latencies and buffer overflows. If this is a problem, then the catchup member can be called to process all outstanding requests.

### virtual void sc::MemoryGrp::deactivate ()` [virtual]`

Deactivate is called after the memory has been used.

Reimplemented in **sc::ARMCIMemoryGrp**, and **sc::MTMPIMemoryGrp**.

### virtual void sc::MemoryGrp::free\_local (void \* data)` [virtual]`

Free data that was allocated with malloc\_local\_double.

Reimplemented in **sc::ARMCIMemoryGrp**.

### static MemoryGrp \* sc::MemoryGrp::get\_default\_memorygrp ()` [static]`

Returns the default memory group. If the default memory group has not yet been set, then one is created. The particular specialization used is determined by configuration options and which specializations are being used for **MessageGrp** and **ThreadGrp**.

### static MemoryGrp \* sc::MemoryGrp::initial\_memorygrp (int & argc, char \*\* argv)` [static]`

Create a memory group. This routine looks for a -memorygrp argument, and then the environmental variable MEMORYGRP to decide which specialization of **MemoryGrp** would be appropriate. The argument to -memorygrp or the value of the environmental variable should be either string for a **ParsedKeyVal** constructor or a classname. The default **ThreadGrp** and **MessageGrp** objects should be initialized before this is called.

References **initial\_memorygrp()**.

Referenced by **initial\_memorygrp()**.

### virtual void \* sc::MemoryGrp::localdata ()` [pure virtual]`

Returns a pointer to the local data.

Implemented in **sc::ActiveMsgMemoryGrp**, **sc::ProcMemoryGrp**, **sc::RDMAMemoryGrp**, and **sc::ShmMemoryGrp**.

### virtual void \* sc::MemoryGrp::malloc\_local (size\_t nbyte)` [virtual]`

Allocate data that will be accessed locally only. Using this for data that will be used for global operation can improve efficiency. Data allocated in this way must be freed with free\_local\_double. \

Reimplemented in **sc::ARMCIMemoryGrp**.

### virtual void \* sc::MemoryGrp::obtain\_readonly (distsize\_t offset, int size)` [pure virtual]`

This gives read access to the memory location. No locking is done.

Implemented in **sc::ActiveMsgMemoryGrp**, **sc::ProcMemoryGrp**, **sc::RDMAMemoryGrp**, and **sc::ShmMemoryGrp**.

### virtual void \* sc::MemoryGrp::obtain\_readwrite (distsize\_t offset, int size)` [pure virtual]`

Only one thread can have an unreleased obtain\_readwrite at a time. The actual memory region locked can be larger than that requested. If the memory region is already locked this will block. For this reason, data should be held as read/write for as short a time as possible.

Implemented in **sc::ActiveMsgMemoryGrp**, **sc::ProcMemoryGrp**, **sc::RDMAMemoryGrp**, and **sc::ShmMemoryGrp**.

### virtual void \* sc::MemoryGrp::obtain\_writeonly (distsize\_t offset, int size)` [pure virtual]`

This gives write access to the memory location. No locking is done.

Implemented in **sc::ActiveMsgMemoryGrp**, **sc::ProcMemoryGrp**, **sc::RDMAMemoryGrp**, and **sc::ShmMemoryGrp**.

### virtual void sc::MemoryGrp::print (std::ostream & o = ExEnv::out0`()`) const` [virtual]`

Prints out information about the object.

Reimplemented from **sc::DescribedClass**.

Reimplemented in **sc::ActiveMsgMemoryGrp**, **sc::ARMCIMemoryGrp**, **sc::RDMAMemoryGrp**, and **sc::ShmMemoryGrp**.

### virtual void sc::MemoryGrp::release\_readonly (void \* data, distsize\_t offset, int size)` [pure virtual]`

This is called when read access is no longer needed.

Implemented in **sc::ActiveMsgMemoryGrp**, **sc::ProcMemoryGrp**, **sc::RDMAMemoryGrp**, and **sc::ShmMemoryGrp**.

### virtual void sc::MemoryGrp::release\_readwrite (void \* data, distsize\_t offset, int size)` [pure virtual]`

This is called when read/write access is no longer needed. The memory will be unlocked.

Implemented in **sc::ActiveMsgMemoryGrp**, **sc::ProcMemoryGrp**, **sc::RDMAMemoryGrp**, and **sc::ShmMemoryGrp**.

### virtual void sc::MemoryGrp::release\_writeonly (void \* data, distsize\_t offset, int size)` [pure virtual]`

This is called when write access is no longer needed.

Implemented in **sc::ActiveMsgMemoryGrp**, **sc::ProcMemoryGrp**, **sc::RDMAMemoryGrp**, and **sc::ShmMemoryGrp**.

### virtual void sc::MemoryGrp::set\_localsize (size\_t)` [pure virtual]`

Set the size of locally held memory. When memory is accessed using a global offset counting starts at node 0 and proceeds up to node **n()** - 1.

Implemented in **sc::MsgMemoryGrp**, **sc::RDMAMemoryGrp**, **sc::ActiveMsgMemoryGrp**, **sc::ARMCIMemoryGrp**, **sc::ProcMemoryGrp**, and **sc::ShmMemoryGrp**.

### virtual void sc::MemoryGrp::sync ()` [pure virtual]`

Synchronizes all the nodes. This is useful after remote memory writes to be certain that all of the writes have completed and the data can be accessed locally, for example.

Implemented in **sc::ARMCIMemoryGrp**, **sc::MsgMemoryGrp**, **sc::MTMPIMemoryGrp**, and **sc::ProcMemoryGrp**.

## Author

Generated automatically by Doxygen for MPQC from the source code.
