OpenFAM Reference Implementation

openfam::fam::fam_fetch_and

Atomically replaces a value in FAM with the Bitwise AND of that value and some given value, and returns the old value.

Synopsis

uint32_t fam_fetch_and(Fam_Descriptor *descriptor, uint64_t offset, uint32_t value);
uint64_t fam_fetch_and(Fam_Descriptor *descriptor, uint64_t offset, uint64_t value);

Description

These methods atomically replace a value in FAM with the Bitwise AND of the value given and the existing value. The old value is returned.

Input Arguments

NameDescription
DescriptorDescriptor associated with the data item.
OffsetOffset within the data item in FAM where value is located.
ValueValue to be combined with the existing value at the given location.

Return Values

The old value from FAM. Throws an exception on error.

Exceptions

ExceptionDescription
Fam_InvalidOption_Exceptionincorrect parameters are passed.
Fam_Datapath_Exceptionerror occurred during atomic operation over fabric.
FAM_ERR_NOPERMCaller does not have access rights.
FAM_ERR_LIBFABRIClibfabric error occurred.
FAM_ERR_NOTFOUNDItem not found in the region.
FAM_ERR_GRPCif there is a communication error with memory server
FAM_ERR_RPC_CLIENT_NOTFOUNDMemory server initialization failure
Fam_Timeout_Exceptionnumber of libfabric retry count reached

Notes

These methods atomically replace a value in FAM with the Bitwise AND of that value and the value given in the method. The old value is returned. Note that the offset argument must point to the correct value for the data type. Availability of these methods is dependent on hardware support for the operations.

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 {
		// look up the descriptor to a previously allocated data item
		Fam_Descriptor *descriptor = myFam->fam_lookup("myItem", "myRegion");
	
		// Atomically replace the first element of the array with
		// the Bitwise AND of it and a value of 0x444
		uint32_t oldValue = myFam->fam_fetch_and(descriptor, 0, 0x0444);

		// The first integer in FAM is now bitwise AND with a value of 0x444
	
		// ... subsequent code here
	} catch (Fam_Exception &e) {
		printf("fam API failed: %d: %s\n", e.fam_error(), e.fam_error_msg());
	}
	
	// ... Finalization code follows
}