Skip to content

Commit

Permalink
Add support for linear systems stored in more partitions than the num…
Browse files Browse the repository at this point in the history
…ber of MPI ranks (#66)

* Add umpire memory pool options to general
* Add IJVectorReadMultipartBinary
* Add IJMatrixReadMultipartBinary
* Add HYPRE_ClearAllErrors call to LS build and preconditioner setup
* Fix dofmap array read for distributed runs
* Update ErrorMsgAdd to be variadic
  • Loading branch information
victorapm authored Jul 11, 2024
1 parent 17d6168 commit 6de515e
Show file tree
Hide file tree
Showing 20 changed files with 885 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.o
*.lo
*.btr
*.csv
.deps
.dirstamp
*.~HEAD~*
Expand Down
7 changes: 4 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ hypredrive_SOURCES = src/main.c
hypredrive_LDADD = libHYPREDRV.la

lib_LTLIBRARIES = libHYPREDRV.la
libHYPREDRV_la_SOURCES = src/error.c src/info.c src/stats.c src/utils.c src/containers.c src/yaml.c src/field.c\
src/linsys.c src/cheby.c src/amg.c src/fsai.c src/ilu.c src/mgr.c src/precon.c src/pcg.c\
src/gmres.c src/fgmres.c src/bicgstab.c src/solver.c src/args.c src/HYPREDRV.c
libHYPREDRV_la_SOURCES = src/error.c src/info.c src/stats.c src/utils.c src/containers.c src/yaml.c\
src/field.c src/vector.c src/matrix.c src/linsys.c src/cheby.c src/amg.c\
src/fsai.c src/ilu.c src/mgr.c src/precon.c src/pcg.c src/gmres.c src/fgmres.c\
src/bicgstab.c src/solver.c src/args.c src/HYPREDRV.c
libHYPREDRV_la_CFLAGS = $(AM_CPPFLAGS) -fvisibility=hidden
libHYPREDRV_la_LDFLAGS = -version-info 0:1:0

Expand Down
8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ dnl Check for libHYPRE
AC_CHECK_LIB([HYPRE], [HYPRE_IJMatrixCreate], [],
[AC_MSG_ERROR([HYPRE library not found or not usable])])

dnl Check for HYPRE headers
AC_CHECK_HEADER([HYPRE_config.h], [],
[AC_MSG_ERROR([HYPRE headers not found or not usable. Please ensure the correct path is specified with --with-hypre-include and the headers are installed.])])

dnl Check for minimum HYPRE version
AC_LANG_PUSH([C])
AC_MSG_CHECKING([for HYPRE version])
Expand All @@ -193,10 +197,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <HYPRE_config.h>],
[AC_MSG_ERROR([HYPRE library version is too old. Use hypre >= 2.31.0])])
AC_LANG_POP([C])

dnl Check for HYPRE headers
AC_CHECK_HEADER([HYPRE_config.h], [],
[AC_MSG_ERROR([HYPRE headers not found or not usable. Please ensure the correct path is specified with --with-hypre-include and the headers are installed.])])

AC_CONFIG_MACRO_DIRS([m4])
AC_CONFIG_HEADERS([HYPREDRV_config.h])
AC_CHECK_HEADERS([stdint.h])
Expand Down
21 changes: 21 additions & 0 deletions docs/usrman-src/input_file_structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ The ``general`` section contains global settings that apply to the entire execut
repeated. Useful for benchmarking and profiling. The default value for this parameter is
`1`.

- ``dev_pool_size`` - Initial size of the umpire's device memory pool. This parameter is
neglected when hypre is *not* configured with umpire support. The default value for this
parameter is `8 GB`.

- ``uvm_pool_size`` - Initial size of the umpire's unified virtual memory pool. This
parameter is neglected when hypre is *not* configured with umpire support. The default
value for this parameter is `8 GB`.

- ``host_pool_size`` - Initial size of the umpire's host memory pool. This parameter is
neglected when hypre is *not* configured with umpire support. The default value for this
parameter is `8 GB`.

- ``pinned_pool_size`` - Initial size of the umpire's host memory pool. This parameter is
neglected when hypre is *not* configured with umpire support. The default value for this
parameter is `512 MB`.


An example code block for the ``general`` section is given below:

.. code-block:: yaml
Expand All @@ -52,6 +69,10 @@ An example code block for the ``general`` section is given below:
statistics: yes
use_millisec: no
num_repetitions: 1
dev_pool_size: 8.0
uvm_pool_size: 8.0
host_pool_size: 8.0
pinned_pool_size: 0.5
Linear System
-------------
Expand Down
4 changes: 4 additions & 0 deletions include/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ typedef struct input_args_struct {
int warmup;
int statistics;
int num_repetitions;
double dev_pool_size;
double uvm_pool_size;
double host_pool_size;
double pinned_pool_size;

LS_args ls;

Expand Down
7 changes: 6 additions & 1 deletion include/containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ typedef struct IntArray_struct
{
int *data;
size_t size;
size_t num_unique_entries;

int *unique_data;
size_t unique_size;

int *g_unique_data;
size_t g_unique_size;
} IntArray;

IntArray* IntArrayCreate(size_t);
Expand Down
6 changes: 4 additions & 2 deletions include/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>

Expand All @@ -33,7 +34,8 @@ typedef enum ErrorCode_enum
ERROR_INVALID_SOLVER = 0x00001000, // 13th bit
ERROR_INVALID_PRECON = 0x00002000, // 14th bit
ERROR_FILE_NOT_FOUND = 0x00004000, // 15th bit
ERROR_UNKNOWN_HYPREDRV_OBJ = 0x00008000, // 16th bit
ERROR_FILE_UNEXPECTED_ENTRY = 0x00008000, // 16th bit
ERROR_UNKNOWN_HYPREDRV_OBJ = 0x00010000, // 17th bit
ERROR_UNKNOWN_TIMING = 0x20000000, // 29th bit
ERROR_UNKNOWN = 0x40000000 // 30th bit
} ErrorCode;
Expand All @@ -49,7 +51,7 @@ bool DistributedErrorCodeActive(MPI_Comm);
/*******************************************************************************
*******************************************************************************/

void ErrorMsgAdd(const char*);
void ErrorMsgAdd(const char*, ...);
void ErrorMsgAddCodeWithCount(ErrorCode, const char*);
void ErrorMsgAddMissingKey(const char*);
void ErrorMsgAddExtraKey(const char*);
Expand Down
3 changes: 3 additions & 0 deletions include/linsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ void LinearSystemComputeResidualNorm(HYPRE_IJMatrix, HYPRE_IJVector, HYPRE_IJVec
long long int LinearSystemMatrixGetNumRows(HYPRE_IJMatrix);
long long int LinearSystemMatrixGetNumNonzeros(HYPRE_IJMatrix);

void IJVectorReadMultipartBinary(const char*, MPI_Comm, uint64_t, HYPRE_IJVector*);
void IJMatrixReadMultipartBinary(const char*, MPI_Comm, uint64_t, HYPRE_IJMatrix*);

#endif /* LINSYS_HEADER */
31 changes: 27 additions & 4 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,43 @@

char* StrToLowerCase(char*);
char* StrTrim(char*);
int CheckBinaryDataExists(const char* prefix);
int CheckBinaryDataExists(const char*);
int CountNumberOfPartitions(const char*);
int ComputeNumberOfDigits(int);
void SplitFilename(const char*, char**, char**);
void CombineFilename(const char*, const char*, char**);

/*******************************************************************************
*******************************************************************************/

/* Helper macros to check if HYPRE_DEVELOP_NUMBER is defined */
#if defined(HYPRE_DEVELOP_NUMBER)
#define HYPRE_DEVELOP_NUMBER_EXISTS 1
#else
#define HYPRE_DEVELOP_NUMBER_EXISTS 0
#endif

/* Check if HYPRE_DEVELOP_NUMBER is greater than a given value */
#define HYPRE_DEVELOP_NUMBER_GT(develop) \
(HYPRE_DEVELOP_NUMBER > (develop))

/* Check if HYPRE_RELEASE_NUMBER is greater than a given value */
#define HYPRE_RELEASE_NUMBER_GT(release) \
(HYPRE_RELEASE_NUMBER > (release))

/* Check for a specific hypre release number and whether
HYPRE_DEVELOP_NUMBER is defined and greater than a given value */
#define HYPRE_RELEASE_NUMBER_EQ_AND_DEVELOP_NUMBER_GT(release, develop) \
(HYPRE_RELEASE_NUMBER == (release) &&\
HYPRE_DEVELOP_NUMBER_EXISTS &&\
HYPRE_DEVELOP_NUMBER_GT(develop))

/* Check for minimum HYPRE version in order to allow certain features */
#define HYPRE_CHECK_MIN_VERSION(release, develop) \
(HYPRE_RELEASE_NUMBER > (release) || \
(HYPRE_RELEASE_NUMBER == (release) && \
(defined(HYPRE_DEVELOP_NUMBER) && HYPRE_DEVELOP_NUMBER > (develop))))
(HYPRE_RELEASE_NUMBER_GT(release) ||\
HYPRE_RELEASE_NUMBER_EQ_AND_DEVELOP_NUMBER_GT(release, develop))

#define GB_TO_BYTES (1 << 30)
#define MAX_DIVISOR_LENGTH 84
#define PRINT_DASHED_LINE(_l) for (size_t i = 0; i < (_l); i++) { printf("-"); } printf("\n");
#define PRINT_EQUAL_LINE(_l) for (size_t i = 0; i < (_l); i++) { printf("="); } printf("\n");
Expand Down
2 changes: 1 addition & 1 deletion include/yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ char* YAMLnodeFindChildValueByKey(YAMLnode*, const char*);
{ \
_node->mapped_val = (char*) malloc(_length * sizeof(char)); \
} \
else if (_length > strlen(_node->mapped_val)) \
else if (_length > (int) strlen(_node->mapped_val)) \
{ \
_node->mapped_val = (char*) realloc(_node->mapped_val, _length * sizeof(char)); \
} \
Expand Down
20 changes: 19 additions & 1 deletion src/HYPREDRV.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,23 @@ HYPREDRV_SetGlobalOptions(HYPREDRV_t obj)
{
HYPRE_SetMemoryLocation(HYPRE_MEMORY_DEVICE);
HYPRE_SetExecutionPolicy(HYPRE_EXEC_DEVICE);
HYPRE_SetSpGemmUseVendor(0);
HYPRE_SetSpGemmUseVendor(0); // TODO: Control this via input option
HYPRE_SetSpMVUseVendor(0); // TODO: Control this via input option

#if defined(HYPRE_USING_UMPIRE)
/* Setup Umpire pools */
HYPRE_SetUmpireDevicePoolName("DEVICE_POOL");
HYPRE_SetUmpireDevicePoolSize(obj->iargs->dev_pool_size);

HYPRE_SetUmpireUMPoolName("UM_POOL");
HYPRE_SetUmpireUMPoolSize(obj->iargs->uvm_pool_size);

HYPRE_SetUmpireHostPoolName("HOST_POOL");
HYPRE_SetUmpireHostPoolSize(obj->iargs->host_pool_size);

HYPRE_SetUmpirePinnedPoolName("PINNED_POOL");
HYPRE_SetUmpirePinnedPoolSize(obj->iargs->pinned_pool_size);
#endif
}
else
{
Expand Down Expand Up @@ -261,6 +277,7 @@ HYPREDRV_LinearSystemBuild(HYPREDRV_t obj)
printf("Solving linear system #%d ", StatsGetLinearSystemID());
printf("with %lld rows and %lld nonzeros...\n", num_rows, num_nonzeros);
}
HYPRE_ClearAllErrors();
}
else
{
Expand Down Expand Up @@ -454,6 +471,7 @@ HYPREDRV_LinearSolverSetup(HYPREDRV_t obj)
SolverSetup(obj->iargs->precon_method, obj->iargs->solver_method,
obj->precon, obj->solver, obj->mat_M, obj->vec_b, obj->vec_x);
}
HYPRE_ClearAllErrors();
}
else
{
Expand Down
28 changes: 24 additions & 4 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ InputArgsCreate(input_args **iargs_ptr)
input_args *iargs = (input_args*) malloc(sizeof(input_args));

/* Set general default options */
iargs->warmup = 0;
iargs->num_repetitions = 1;
iargs->statistics = 1;
iargs->warmup = 0;
iargs->num_repetitions = 1;
iargs->statistics = 1;
iargs->dev_pool_size = 8.0 * GB_TO_BYTES;
iargs->uvm_pool_size = 8.0 * GB_TO_BYTES;
iargs->host_pool_size = 8.0 * GB_TO_BYTES;
iargs->pinned_pool_size = 0.5 * GB_TO_BYTES;

/* Set default Linear System options */
LinearSystemSetDefaultArgs(&iargs->ls);
Expand Down Expand Up @@ -126,7 +130,23 @@ InputArgsParseGeneral(input_args *iargs, YAMLtree *tree)
}
else if (!strcmp(child->key, "num_repetitions"))
{
iargs->num_repetitions = (HYPRE_Int) atoi(child->val);
iargs->num_repetitions = atoi(child->val);
}
else if (!strcmp(child->key, "dev_pool_size"))
{
iargs->dev_pool_size = GB_TO_BYTES * atof(child->val);
}
else if (!strcmp(child->key, "uvm_pool_size"))
{
iargs->uvm_pool_size = GB_TO_BYTES * atof(child->val);
}
else if (!strcmp(child->key, "host_pool_size"))
{
iargs->host_pool_size = GB_TO_BYTES * atof(child->val);
}
else if (!strcmp(child->key, "pinned_pool_size"))
{
iargs->pinned_pool_size = GB_TO_BYTES * atof(child->val);
}
else
{
Expand Down
Loading

0 comments on commit 6de515e

Please sign in to comment.