OpenFAM Reference Implementation

openfam::fam::fam_close

Close the descriptor of a data item in FAM.

Synopsis

void fam_close(Fam_Descriptor *descriptor);

Description

This method reduces the reference count of the region within which the data item represented by the descriptor is allocated. OpenFAM internally uses this reference count for optimal usage of resources. Fam_close() helps to release unused resources back to the system.

Input Arguments

NameDescription
descriptorDescriptor associated with the space to deallocate.

Return Values

None. Throws Fam_Exception on error.

Fam Error Numbers

ErrorDescription
FAM_ERR_NOPERMCaller does not have access rights.
FAM_ERR_NOTFOUNDItem or region name was not found by the metadata service.
FAM_ERR_RPCCommunication error from grpc layer.
FAM_ERR_RPC_CLIENT_NOTFOUNDRPC service not available.
FAM_ERR_METADATAMetadata service error.
FAM_ERR_MEMORYMemory service error.
FAM_ERR_RESOURCEResource not available.

Notes

There is no explicit open method for a data item descriptor. The reference count of a region is increased when a PE obtains a valid descriptor for a data item belonging to that region (either when data item is allocated or while validating the descriptor in any data path or atomic API call).

Example

#include <string.h>
#include <fam/fam.h>
#include <fam/fam_exception.h>
using namespace std;
using namespace openfam;

int main(void) {
	fam *myFam = new fam();
	
	// ... initialization code here
	
	try {
		// get a region descriptor from the metadata service
		Fam_Region_Descriptor *region = myFam->fam_lookup_region("myRegion");

                // create 50 element unnamed integer array in FAM with 0600
		// (read/write by owner) permissions in myRegion
		Fam_Descriptor *descriptor = myFam->fam_allocate((uint64_t)(50 * sizeof(int)), 0600, region);

		printf("Successfully allocated 50 unnamed integer elements\n");

		// close the descriptor
		myFam->fam_close(descriptor);
		printf("Successfully closed the data item descriptor\n");
		

		
	} catch (Fam_Exception &e) {
		printf("Fam API failed: %d: %s\n", e.fam_error(), e.fam_error_msg());
	}
		
	// ... Finalization code here
}