common_memory.c

Part of a parallel direct block solver.

This module handles errors.

Authors

Mathieu Favergefav.nosp@m.erge@labr.nosp@m.i.fr
Xavier LACOSTElac.nosp@m.oste@labr.nosp@m.i.fr
Francois PELLEGRINI.

Dates

Version 0.0from 07 sep 2001 to 07 sep 2001
Version 0.1from 14 apr 2001 to 24 mar 2003
Version 1.3from 25 feb 2004 to 25 feb 2004
Summary
common_memory.cPart of a parallel direct block solver.
VariablesThe static variables.
memallocmutexflagBoolean indicating if memallocmutexdat mutex has been initialized.
memalloccurrentCurrent memory allocated using memAlloc_func.
memallocmaxMaximum value of memalloccurrent since the program started.
memalloctraceflagBoolean indicating if we want to trace allocation.
time_stampOrigin of traces.
trace_procnumProcessor tracing allocations.
memallocmutexdatLocal mutex
memalloctraceflag
trace_timestamp
trace_procnum
FunctionsThe memory handling routines.
memAllocaTraceStart tracing memory.
memAllocTrace
memAllocUntraceStop tracing allocations.
memAllocGetCurrentGet the current memory allocated.
memAllocGetMaxGet the maximu memory allocated.
memAllocTraceResetRestarts tracing allocation with reseting memallocmax.
memAlloc_funcThis is a thread-safe memory allocation routine.
memReallocThis is a thread-safe memory reallocation routine.
memFreeThis is a thread-safe memory deallocation routine.
memAllocGroupThis routine allocates a set of arrays in a single memAlloc()’ed array, the address of which is placed in the first argument.
memAllocGroupThis routine reallocates a set of arrays in a single memRealloc()’ed array passed as first argument, and the address of which is placed in the second argument.
memOffsetThis routine computes the offsets of arrays of given sizes and types with respect to a given base address passed as first argument.

Variables

The static variables.

memallocmutexflag

static int memallocmutexflag

Boolean indicating if memallocmutexdat mutex has been initialized.

pthread_mutex_t: memallocmutexdat mutex protecting memalloccurrent, memallocmax, memalloctraceflag, <trace_file>, trace_timestamp and trace_procnum

memalloccurrent

Current memory allocated using memAlloc_func.

memallocmax

Maximum value of memalloccurrent since the program started.

memalloctraceflag

Boolean indicating if we want to trace allocation.

stream: trace_file File into which to write traces.

time_stamp

Origin of traces.

trace_procnum

Processor tracing allocations.

memallocmutexdat

static pthread_mutex_t memallocmutexdat

Local mutex

memalloctraceflag

int memalloctraceflag

trace_timestamp

static double trace_timestamp

trace_procnum

static int trace_procnum

Functions

The memory handling routines.

memAllocaTrace

Start tracing memory.

Initialize memallocmutexdat if not done.

Defines all tracing variables.

Parameters

fileStream where to write traces, opened in write mode.
timestampTraces origin.
procnumProcessor writting traces.

Returns

voidIn all cases.

memAllocTrace

void memAllocTrace (FILE *file,
double timestamp,
int procnum)

memAllocUntrace

void memAllocUntrace ()

Stop tracing allocations.

Returns

voidin all cases.

memAllocGetCurrent

Get the current memory allocated.

Returns

memalloccurrent value.

memAllocGetMax

Get the maximu memory allocated.

Returns

memallocmax value.

memAllocTraceReset

void memAllocTraceReset ()

Restarts tracing allocation with reseting memallocmax.

Returns

voidin all cases.

memAlloc_func

This is a thread-safe memory allocation routine.

Parameters

sizeMemory size wanted.
filenameUsed for error message, file where the function is called.
lineUsed for erro message, line where the function is called.

Returns

!NULLpointer to memory block.
NULLno array allocated.

memRealloc

This is a thread-safe memory reallocation routine.

Parameters

memptraddress of the array to realloc.
sizeNew size wanted.

Returns

!NULLpointer to memory block.
NULLno array allocated.

memFree

void memFree (void *memptr)

This is a thread-safe memory deallocation routine.

It returns

voidin all cases

memAllocGroup

This routine allocates a set of arrays in a single memAlloc()’ed array, the address of which is placed in the first argument.  Arrays to be allocated are described as a duplet of ..., &ptr, size, ..., terminated by a NULL pointer.

Parameters

memptrPointer to first argument to allocate
...list of duplets &ptr, size, starting by size and ending by size.

Returns

!NULLpointer to block, all arrays allocated.
NULLno array allocated.

memAllocGroup

This routine reallocates a set of arrays in a single memRealloc()’ed array passed as first argument, and the address of which is placed in the second argument.  Arrays to be allocated are described as a duplet of ..., &ptr, size, ..., terminated by a NULL pointer.  WARNING: Because of memory alignment issues between int and double values, when arrays are not reallocated in place, offsets of arrays may vary, so that one should rather compute differences with respect to original offsets than rely on offsets returned by the routine.  This routine should be used with extreme caution!

Parameters

oldptrPointer to first block to reallocate.
...list of duplets &ptr, size, starting by size and ending by size.

Returns

!NULLpointer to block, all arrays allocated.
NULLno array allocated.

memOffset

This routine computes the offsets of arrays of given sizes and types with respect to a given base address passed as first argument.  Arrays the offsets of which are to be computed are described as a duplet of ..., &ptr, size, ..., terminated by a NULL pointer.

Parameters

memptrPointer to base address of memory area.
...list of duplets &ptr, size, starting by size and ending by size.

Returns

!NULLin all cases, pointer to the end of the memory area.
static int memallocmutexflag
Boolean indicating if memallocmutexdat mutex has been initialized.
static pthread_mutex_t memallocmutexdat
Local mutex
This is a thread-safe memory allocation routine.
int memalloctraceflag
static double trace_timestamp
static int trace_procnum
void memAllocTrace (FILE *file,
double timestamp,
int procnum)
void memAllocUntrace ()
Stop tracing allocations.
void memAllocTraceReset ()
Restarts tracing allocation with reseting memallocmax.
Maximum value of memalloccurrent since the program started.
void memFree (void *memptr)
This is a thread-safe memory deallocation routine.
Current memory allocated using memAlloc_func.
Close