Skip to content

Commit

Permalink
add get_mem
Browse files Browse the repository at this point in the history
  • Loading branch information
huiscliu committed Mar 17, 2019
1 parent 7f40a22 commit d74884b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
Binary file modified doc/sxamg.pdf
Binary file not shown.
9 changes: 7 additions & 2 deletions doc/utils.tex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ \section{Memory}

\section{Performance}

\nverb{sx_gettime} returns current time stamp.
\nverb{sx_get_time} returns current time stamp.
\begin{evb}
SX_FLT sx_gettime(void);
SX_FLT sx_get_time(void);
\end{evb}

\nverb{sx_get_mem} returns current memory usage.
\begin{evb}
SX_FLT sx_get_mem(void);
\end{evb}
4 changes: 2 additions & 2 deletions example/cg-amg.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int main(void)
sx_printf("Initial residual: %"fFMTe"\n\n", err0);

/* timer */
stm = sx_gettime();
stm = sx_get_time();

for (i = 0; i < maxits; i++) {
/* supposed to solve preconditioning system Mz = r */
Expand Down Expand Up @@ -149,7 +149,7 @@ int main(void)
sx_printf("\ncg failed to converge.\n\n");
}
else {
stm = sx_gettime() - stm;
stm = sx_get_time() - stm;

sx_printf("\ncg converged: absolute residual: %"fFMTe
", total iterations: %"dFMT", time: %g s\n\n", err, i + 1, stm);
Expand Down
4 changes: 3 additions & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ void * sx_calloc(size_t size, SX_INT type);
void * sx_realloc(void *oldmem, size_t tsize);
void sx_free(void *mem);

SX_FLT sx_gettime(void);
SX_FLT sx_get_time(void);
SX_FLT sx_get_mem(void);

void sx_exit_on_errcode(const SX_INT status, const char *fctname);

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions src/amg-setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void sx_amg_setup(SX_AMG *mg, SX_MAT *A, SX_AMG_PARS *pars)
max_lvls = pars->max_levels;

/* timer */
setup_start = sx_gettime();
setup_start = sx_get_time();

/* create mg */
assert(mg != NULL);
Expand Down Expand Up @@ -138,7 +138,7 @@ void sx_amg_setup(SX_AMG *mg, SX_MAT *A, SX_AMG_PARS *pars)
sx_ivec_destroy(&vertices);

if (verb > 1) {
setup_end = sx_gettime();
setup_end = sx_get_time();

sx_amg_complexity_print(mg);
sx_printf("AMG setup time: %"fFMTg" s\n", setup_end - setup_start);
Expand Down
8 changes: 4 additions & 4 deletions src/sxamg.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SX_RTN sx_solver_amg_solve(SX_AMG *mg, SX_VEC *x, SX_VEC *b)
sumb = sx_blas_vec_norm2(b); // L2norm(b)
absres0 = sumb;

solve_start = sx_gettime();
solve_start = sx_get_time();

// Print iteration information if needed
sx_print_itinfo(verb, STOP_REL_RES, iter, 1.0, sumb, 0.0);
Expand Down Expand Up @@ -81,7 +81,7 @@ SX_RTN sx_solver_amg_solve(SX_AMG *mg, SX_VEC *x, SX_VEC *b)
}

if (verb > 0) {
solve_end = sx_gettime();
solve_end = sx_get_time();
sx_printf("AMG solve time: %"fFMTg" s\n", solve_end - solve_start);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ SX_RTN sx_solver_amg(SX_MAT *A, SX_VEC *x, SX_VEC *b, SX_AMG_PARS *pars)
m = A->num_rows;
n = A->num_cols;

if (verb > 0) AMG_start = sx_gettime();
if (verb > 0) AMG_start = sx_get_time();

// check matrix data
if (m != n) {
Expand All @@ -166,7 +166,7 @@ SX_RTN sx_solver_amg(SX_MAT *A, SX_VEC *x, SX_VEC *b, SX_AMG_PARS *pars)

// print out CPU time if needed
if (verb > 0) {
AMG_end = sx_gettime();
AMG_end = sx_get_time();
sx_printf("AMG totally time: %"fFMTg" s\n", AMG_end - AMG_start);
}

Expand Down
18 changes: 15 additions & 3 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ void sx_free(void *mem)
}

/**
* \fn sx_gettime (SX_FLT *time)
* \fn sx_get_time (SX_FLT *time)
*
* \brief Get system time
*
*/
#if USE_UNIX
SX_FLT sx_gettime(void)
SX_FLT sx_get_time(void)
{
struct timeval tv;
double t;
Expand All @@ -167,7 +167,7 @@ SX_FLT sx_gettime(void)
#else
#include <windows.h>

SX_FLT sx_gettime()
SX_FLT sx_get_time(void)
{
LARGE_INTEGER timer;
static LARGE_INTEGER fre;
Expand All @@ -187,6 +187,18 @@ SX_FLT sx_gettime()
}
#endif

SX_FLT sx_get_mem(void)
{
struct rusage RU;
SX_FLT mem_current;

/* getrusage() */
getrusage(RUSAGE_SELF, &RU);
mem_current = RU.ru_maxrss / (double)1024.;

return mem_current;
}

/**
* \fn void sx_exit_on_errcode (const SX_INT status, const char *fctname)
*
Expand Down

0 comments on commit d74884b

Please sign in to comment.