Fix memory tracker with omp (#844)
This PR fixes hypre memory tracker with OMP threading.
This commit is contained in:
parent
1eabaf5f33
commit
2391e4703f
@ -914,6 +914,8 @@ typedef struct
|
|||||||
hypre_MemoryTrackerQueue queue[HYPRE_MEMORY_NUM_EVENTS];
|
hypre_MemoryTrackerQueue queue[HYPRE_MEMORY_NUM_EVENTS];
|
||||||
} hypre_MemoryTracker;
|
} hypre_MemoryTracker;
|
||||||
|
|
||||||
|
extern hypre_MemoryTracker *_hypre_memory_tracker;
|
||||||
|
|
||||||
#define hypre_TAlloc(type, count, location) \
|
#define hypre_TAlloc(type, count, location) \
|
||||||
( \
|
( \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
@ -8,22 +8,6 @@
|
|||||||
#include "_hypre_utilities.h"
|
#include "_hypre_utilities.h"
|
||||||
#include "_hypre_utilities.hpp"
|
#include "_hypre_utilities.hpp"
|
||||||
|
|
||||||
#ifdef HYPRE_USING_MEMORY_TRACKER
|
|
||||||
hypre_MemoryTracker *_hypre_memory_tracker = NULL;
|
|
||||||
|
|
||||||
/* accessor to the global ``_hypre_memory_tracker'' */
|
|
||||||
hypre_MemoryTracker*
|
|
||||||
hypre_memory_tracker(void)
|
|
||||||
{
|
|
||||||
if (!_hypre_memory_tracker)
|
|
||||||
{
|
|
||||||
_hypre_memory_tracker = hypre_MemoryTrackerCreate();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _hypre_memory_tracker;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* global variable _hypre_handle:
|
/* global variable _hypre_handle:
|
||||||
* Outside this file, do NOT access it directly,
|
* Outside this file, do NOT access it directly,
|
||||||
* but use hypre_handle() instead (see handle.h) */
|
* but use hypre_handle() instead (see handle.h) */
|
||||||
|
|||||||
@ -16,6 +16,25 @@
|
|||||||
|
|
||||||
#if defined(HYPRE_USING_MEMORY_TRACKER)
|
#if defined(HYPRE_USING_MEMORY_TRACKER)
|
||||||
|
|
||||||
|
hypre_MemoryTracker *_hypre_memory_tracker = NULL;
|
||||||
|
|
||||||
|
/* accessor to the global ``_hypre_memory_tracker'' */
|
||||||
|
hypre_MemoryTracker*
|
||||||
|
hypre_memory_tracker(void)
|
||||||
|
{
|
||||||
|
#ifdef HYPRE_USING_OPENMP
|
||||||
|
#pragma omp critical
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
if (!_hypre_memory_tracker)
|
||||||
|
{
|
||||||
|
_hypre_memory_tracker = hypre_MemoryTrackerCreate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _hypre_memory_tracker;
|
||||||
|
}
|
||||||
|
|
||||||
size_t hypre_total_bytes[hypre_NUM_MEMORY_LOCATION];
|
size_t hypre_total_bytes[hypre_NUM_MEMORY_LOCATION];
|
||||||
size_t hypre_peak_bytes[hypre_NUM_MEMORY_LOCATION];
|
size_t hypre_peak_bytes[hypre_NUM_MEMORY_LOCATION];
|
||||||
size_t hypre_current_bytes[hypre_NUM_MEMORY_LOCATION];
|
size_t hypre_current_bytes[hypre_NUM_MEMORY_LOCATION];
|
||||||
@ -252,44 +271,49 @@ hypre_MemoryTrackerInsert2(const char *action,
|
|||||||
|
|
||||||
hypre_MemoryTrackerQueue *queue = &tracker->queue[q];
|
hypre_MemoryTrackerQueue *queue = &tracker->queue[q];
|
||||||
|
|
||||||
/* resize if not enough space */
|
#ifdef HYPRE_USING_OPENMP
|
||||||
|
#pragma omp critical
|
||||||
if (queue->alloced_size <= queue->actual_size)
|
#endif
|
||||||
{
|
{
|
||||||
queue->alloced_size = 2 * queue->alloced_size + 1;
|
/* resize if not enough space */
|
||||||
queue->data = (hypre_MemoryTrackerEntry *) realloc(queue->data,
|
|
||||||
queue->alloced_size * sizeof(hypre_MemoryTrackerEntry));
|
|
||||||
}
|
|
||||||
|
|
||||||
hypre_assert(queue->actual_size < queue->alloced_size);
|
if (queue->alloced_size <= queue->actual_size)
|
||||||
|
{
|
||||||
|
queue->alloced_size = 2 * queue->alloced_size + 1;
|
||||||
|
queue->data = (hypre_MemoryTrackerEntry *) realloc(queue->data,
|
||||||
|
queue->alloced_size * sizeof(hypre_MemoryTrackerEntry));
|
||||||
|
}
|
||||||
|
|
||||||
/* insert an entry */
|
hypre_assert(queue->actual_size < queue->alloced_size);
|
||||||
hypre_MemoryTrackerEntry *entry = queue->data + queue->actual_size;
|
|
||||||
|
|
||||||
entry->index = queue->actual_size;
|
/* insert an entry */
|
||||||
entry->time_step = tracker->curr_time_step;
|
hypre_MemoryTrackerEntry *entry = queue->data + queue->actual_size;
|
||||||
sprintf(entry->action, "%s", action);
|
|
||||||
entry->ptr = ptr;
|
entry->index = queue->actual_size;
|
||||||
entry->ptr2 = ptr2;
|
entry->time_step = tracker->curr_time_step;
|
||||||
entry->nbytes = nbytes;
|
sprintf(entry->action, "%s", action);
|
||||||
entry->memory_location = memory_location;
|
entry->ptr = ptr;
|
||||||
entry->memory_location2 = memory_location2;
|
entry->ptr2 = ptr2;
|
||||||
sprintf(entry->filename, "%s", filename);
|
entry->nbytes = nbytes;
|
||||||
sprintf(entry->function, "%s", function);
|
entry->memory_location = memory_location;
|
||||||
entry->line = line;
|
entry->memory_location2 = memory_location2;
|
||||||
entry->pair = (size_t) -1;
|
sprintf(entry->filename, "%s", filename);
|
||||||
|
sprintf(entry->function, "%s", function);
|
||||||
|
entry->line = line;
|
||||||
|
entry->pair = (size_t) -1;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
HYPRE_Int myid;
|
HYPRE_Int myid;
|
||||||
hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD, &myid);
|
hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD, &myid);
|
||||||
if (myid == 0 && entry->time_step == 28111) {assert(0);}
|
if (myid == 0 && entry->time_step == 28111) {assert(0);}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* increase the time step */
|
/* increase the time step */
|
||||||
tracker->curr_time_step ++;
|
tracker->curr_time_step ++;
|
||||||
|
|
||||||
/* increase the queue length by 1 */
|
/* increase the queue length by 1 */
|
||||||
queue->actual_size ++;
|
queue->actual_size ++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HYPRE_Int
|
HYPRE_Int
|
||||||
|
|||||||
@ -69,6 +69,8 @@ typedef struct
|
|||||||
hypre_MemoryTrackerQueue queue[HYPRE_MEMORY_NUM_EVENTS];
|
hypre_MemoryTrackerQueue queue[HYPRE_MEMORY_NUM_EVENTS];
|
||||||
} hypre_MemoryTracker;
|
} hypre_MemoryTracker;
|
||||||
|
|
||||||
|
extern hypre_MemoryTracker *_hypre_memory_tracker;
|
||||||
|
|
||||||
#define hypre_TAlloc(type, count, location) \
|
#define hypre_TAlloc(type, count, location) \
|
||||||
( \
|
( \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user