本文整理汇总了C++中CHECK_MALLOC函数的典型用法代码示例。如果您正苦于以下问题:C++ CHECK_MALLOC函数的具体用法?C++ CHECK_MALLOC怎么用?C++ CHECK_MALLOC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CHECK_MALLOC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Destroy_LU
/*! \brief Destroy distributed L & U matrices. */
void
Destroy_LU(int_t n, gridinfo_t *grid, LUstruct_t *LUstruct)
{
int_t i, nb, nsupers;
Glu_persist_t *Glu_persist = LUstruct->Glu_persist;
LocalLU_t *Llu = LUstruct->Llu;
#if ( DEBUGlevel>=1 )
int iam;
MPI_Comm_rank( MPI_COMM_WORLD, &iam );
CHECK_MALLOC(iam, "Enter Destroy_LU()");
#endif
nsupers = Glu_persist->supno[n-1] + 1;
nb = CEILING(nsupers, grid->npcol);
for (i = 0; i < nb; ++i)
if ( Llu->Lrowind_bc_ptr[i] ) {
SUPERLU_FREE (Llu->Lrowind_bc_ptr[i]);
#ifdef GPU_ACC
checkCuda(cudaFreeHost(Llu->Lnzval_bc_ptr[i]));
#else
SUPERLU_FREE (Llu->Lnzval_bc_ptr[i]);
#endif
}
SUPERLU_FREE (Llu->Lrowind_bc_ptr);
SUPERLU_FREE (Llu->Lnzval_bc_ptr);
nb = CEILING(nsupers, grid->nprow);
for (i = 0; i < nb; ++i)
if ( Llu->Ufstnz_br_ptr[i] ) {
SUPERLU_FREE (Llu->Ufstnz_br_ptr[i]);
SUPERLU_FREE (Llu->Unzval_br_ptr[i]);
}
SUPERLU_FREE (Llu->Ufstnz_br_ptr);
SUPERLU_FREE (Llu->Unzval_br_ptr);
/* The following can be freed after factorization. */
SUPERLU_FREE(Llu->ToRecv);
SUPERLU_FREE(Llu->ToSendD);
SUPERLU_FREE(Llu->ToSendR[0]);
SUPERLU_FREE(Llu->ToSendR);
/* The following can be freed only after iterative refinement. */
SUPERLU_FREE(Llu->ilsum);
SUPERLU_FREE(Llu->fmod);
SUPERLU_FREE(Llu->fsendx_plist[0]);
SUPERLU_FREE(Llu->fsendx_plist);
SUPERLU_FREE(Llu->bmod);
SUPERLU_FREE(Llu->bsendx_plist[0]);
SUPERLU_FREE(Llu->bsendx_plist);
SUPERLU_FREE(Llu->mod_bit);
SUPERLU_FREE(Glu_persist->xsup);
SUPERLU_FREE(Glu_persist->supno);
#if ( DEBUGlevel>=1 )
CHECK_MALLOC(iam, "Exit Destroy_LU()");
#endif
}
示例2: solve_res_3ft_matrix
/* solve natural resistance problem in FT version
* for both periodic and non-periodic boundary conditions
* INPUT
* sys : system parameters
* u [np * 3] : in the labo frame.
* o [np * 3] : in the labo frame.
* OUTPUT
* f [np * 3] :
* t [np * 3] :
*/
void
solve_res_3ft_matrix (struct stokes * sys,
const double *u, const double *o,
double *f, double *t)
{
if (sys->version != 1)
{
fprintf (stderr, "libstokes solve_res_3ft_matrix :"
" the version is wrong. reset to FT\n");
sys->version = 1;
}
int np = sys->np;
double *u0 = (double *) malloc (sizeof (double) * np * 3);
double *o0 = (double *) malloc (sizeof (double) * np * 3);
CHECK_MALLOC (u0, "solve_res_3ft_matrix");
CHECK_MALLOC (o0, "solve_res_3ft_matrix");
shift_labo_to_rest_U (sys, np, u, u0);
shift_labo_to_rest_O (sys, np, o, o0);
/* the main calculation is done in the the fluid-rest frame;
* u(x)=0 as |x|-> infty */
solve_res_3ft_matrix_0 (sys,
u0, o0,
f, t);
free (u0);
free (o0);
/* for the interface, we are in the labo frame, that is
* u(x) is given by the imposed flow field as |x|-> infty */
// here, no velocity in output, we do nothing
}
示例3: strtab_create
/*
* strtab_create: Return pointer to strtab; to be passed to strtab_insert()
* and strtab_free().
*/
STRTAB *
strtab_create(void)
{
STRTAB *strtab;
/*
* Set alignSize to one less thatn the least power of 2 greater or
* equal to IDSIZE.
* This is assumed to be the maximum required alignment for this type.
*/
if (alignSize == 0) { /* first time only */
alignSize = 1;
while (alignSize < IDSIZE)
alignSize <<= 1;
--alignSize;
}
strtab = (STRTAB *) malloc(sizeof *strtab);
CHECK_MALLOC(strtab);
strtab->buf_list = NULL;
strtab->buf_ptr = NULL;
strtab->size = 0;
strtab->index = (TABLE *) table_create(strcmp);
if (strtab->index == NULL) {
free(strtab);
return (NULL);
}
strtab->upfix = (void *) upfix_init(UPFIX_MAX_LEN, NULL);
CHECK_MALLOC(strtab->upfix);
return strtab;
}
示例4: fastSI_GSL_MULTIROOT_func
/* wrapper of fastSI_f() for GSL-MULTROOT routine
*/
int
fastSI_GSL_MULTIROOT_func (const gsl_vector *x, void *p,
gsl_vector *f)
{
struct BD_imp *b = (struct BD_imp *)p;
int np3 = 3 * b->BD->sys->np;
double *xcur = (double *)malloc (sizeof (double) * np3);
double *fcur = (double *)malloc (sizeof (double) * np3);
CHECK_MALLOC (xcur, "fastSI_GSL_MULTIROOT_func");
CHECK_MALLOC (fcur, "fastSI_GSL_MULTIROOT_func");
int i;
for (i = 0; i < np3; i ++)
{
xcur[i] = gsl_vector_get (x, i);
}
fastSI_f (b, xcur, fcur);
for (i = 0; i < np3; i ++)
{
gsl_vector_set (f, i, fcur[i]);
}
free (xcur);
free (fcur);
return (GSL_SUCCESS);
}
示例5: cf_openOut
struct cfile *
cf_openOut(const char *path)
{
struct cfile *cf;
cf = (struct cfile *) malloc(sizeof *cf);
CHECK_MALLOC(cf);
cf->fp = fopen(path, "w");
if (cf->fp == NULL) {
free(cf);
return NULL;
}
cf->fileName = (char *) malloc(strlen(path) + 1);
CHECK_MALLOC(cf->fileName);
strcpy(cf->fileName, path);
cf->mode = W_MODE; /* read */
cf->lineNo = 0;
cf->pendingCount = 0;
cf->pendingValue = -1;
cf->atFirstChar = 1;
return cf;
}
示例6: EV_LJ_init
/* initialize struct EV_LJ
* INPUT
* np : number of particles
* OUTPUT
* returned value : struct EV_LJ,
* where LJ parameters are set by zero.
*/
struct EV_LJ *
EV_LJ_init (int np)
{
struct EV_LJ *ev_LJ = (struct EV_LJ *)malloc (sizeof (struct EV_LJ));
CHECK_MALLOC (ev_LJ, "EV_LJ_init");
ev_LJ->n = np;
ev_LJ->flag = (int *)malloc (sizeof (int) * np);
ev_LJ->e = (double *)malloc (sizeof (double) * np);
ev_LJ->r0 = (double *)malloc (sizeof (double) * np);
CHECK_MALLOC (ev_LJ->flag, "EV_LJ_init");
CHECK_MALLOC (ev_LJ->e, "EV_LJ_init");
CHECK_MALLOC (ev_LJ->r0, "EV_LJ_init");
// zero clear
int i;
for (i = 0; i < np; i ++)
{
ev_LJ->flag[i] = 0;
ev_LJ->e [i] = 0.0;
ev_LJ->r0 [i] = 0.0;
}
return (ev_LJ);
}
示例7: BONDS_GROUP_set
void
BONDS_GROUP_set (struct BONDS_GROUP *g,
int np,
const int *ip,
const int *bonds)
{
if (np == 0) return;
g->np = np;
g->ip = (int *)malloc (sizeof (int) * np);
CHECK_MALLOC (g->ip, "BONDS_GROUP_set");
int i;
for (i = 0; i < np; i ++)
{
g->ip[i] = ip[i];
}
if (np == 1)
{
g->bonds = NULL;
}
else
{
g->bonds = (int *)malloc (sizeof (int) * (np-1));
CHECK_MALLOC (g->bonds, "BONDS_GROUP_set");
}
for (i = 0; i < np-1; i ++)
{
g->bonds[i] = bonds[i];
}
}
示例8: check_KIrand_Gaussian
/* check KIrand_Gaussian()
*/
int
check_KIrand_Gaussian (int verbose, double tiny)
{
if (verbose != 0)
{
fprintf (stdout,
"==================================================\n"
"check_KIrand_Gaussian : start\n");
}
int check = 0;
double max = 0.0;
int n = 1000000;
double *x0 = (double *)malloc (sizeof (double) * n);
CHECK_MALLOC (x0, "check_KIrand_Gaussian");
int i;
unsigned long seed = 0;
struct KIrand *rng = KIrand_init ();
CHECK_MALLOC (rng, "check_KIrand_Gaussian");
KIrand_init_genrand (rng, seed);
for (i = 0; i < n; i ++)
{
x0[i] = KIrand_Gaussian (rng);
}
KIrand_free (rng);
// check for Gaussian properties
double mean = 0.0;
for (i = 0; i < n; i ++)
{
mean += x0[i];
}
mean /= (double)n;
double vari = 0.0;
for (i = 0; i < n; i ++)
{
vari += (x0[i] - mean) * (x0[i] - mean);
}
vari /= (double)n;
check += compare_max (mean+1.0, 1.0, " mean", verbose, tiny, &max);
check += compare_max (vari, 1.0, " vari", verbose, tiny, &max);
free (x0);
if (verbose != 0)
{
fprintf (stdout, " max error = %e vs tiny = %e\n", max, tiny);
if (check == 0) fprintf (stdout, " => PASSED\n\n");
else fprintf (stdout, " => FAILED\n\n");
}
return (check);
}
示例9: solve_res_lub_3ft_matrix_0
/* solve natural resistance problem in FT version in the fluid-rest frame
* for both periodic and non-periodic boundary conditions
* INPUT
* sys : system parameters
* u [np * 3] : = U - u^inf, that is, in the fluid-rest frame
* o [np * 3] : = O - O^inf, that is, in the fluid-rest frame
* OUTPUT
* f [np * 3] :
* t [np * 3] :
*/
void
solve_res_lub_3ft_matrix_0 (struct stokes * sys,
const double *u, const double *o,
double *f, double *t)
{
if (sys->version != 1)
{
fprintf (stderr, "libstokes solve_res_lub_3ft_matrix_0 :"
" the version is wrong. reset to FT\n");
sys->version = 1;
}
int np = sys->np;
int n6 = np * 6;
double *mob = (double *) malloc (sizeof (double) * n6 * n6);
double *lub = (double *) malloc (sizeof (double) * n6 * n6);
double *b = (double *) malloc (sizeof (double) * n6);
double *x = (double *) malloc (sizeof (double) * n6);
CHECK_MALLOC (mob, "solve_res_lub_3ft_matrix");
CHECK_MALLOC (lub, "solve_res_lub_3ft_matrix");
CHECK_MALLOC (b, "solve_res_lub_3ft_matrix");
CHECK_MALLOC (x, "solve_res_lub_3ft_matrix");
// M matrix
make_matrix_mob_3all (sys, mob); // sys->version is 1 (FT)
// M^-1
lapack_inv_ (n6, mob);
// L matrix
make_matrix_lub_3ft (sys, lub);
// M^-1 + L
int i;
for (i = 0; i < n6 * n6; i ++)
{
lub [i] += mob [i];
}
free (mob);
/* b := (UO) */
set_ft_by_FT (np, b, u, o);
// x := (M^-1 + L).(UO)
dot_prod_matrix (lub, n6, n6, b, x);
// (FT) = x
set_FT_by_ft (np, f, t, x);
free (lub);
free (b);
free (x);
}
示例10: fd_dictfct_Address_encode
int fd_dictfct_Address_encode(void * data, union avp_value * avp_value)
{
sSS * ss = (sSS *) data;
uint16_t AddressType = 0;
size_t size = 0;
unsigned char * buf = NULL;
TRACE_ENTRY("%p %p", data, avp_value);
CHECK_PARAMS( data && avp_value );
switch (ss->ss_family) {
case AF_INET:
{
/* We are encoding an IP address */
sSA4 * sin = (sSA4 *)ss;
AddressType = 1;/* see http://www.iana.org/assignments/address-family-numbers/ */
size = 6; /* 2 for AddressType + 4 for data */
CHECK_MALLOC( buf = malloc(size) );
/* may not work because of alignment: *(uint32_t *)(buf+2) = htonl(sin->sin_addr.s_addr); */
memcpy(buf + 2, &sin->sin_addr.s_addr, 4);
}
break;
case AF_INET6:
{
/* We are encoding an IPv6 address */
sSA6 * sin6 = (sSA6 *)ss;
AddressType = 2;/* see http://www.iana.org/assignments/address-family-numbers/ */
size = 18; /* 2 for AddressType + 16 for data */
CHECK_MALLOC( buf = malloc(size) );
/* The order is already good here */
memcpy(buf + 2, &sin6->sin6_addr.s6_addr, 16);
}
break;
default:
CHECK_PARAMS( AddressType = 0 );
}
*(uint16_t *)buf = htons(AddressType);
avp_value->os.len = size;
avp_value->os.data = buf;
return 0;
}
示例11: solve_mix_3ft_noHI
/* solve natural mobility problem with fixed particles in FT version
* without HI
* for both periodic and non-periodic boundary conditions
* INPUT
* sys : system parameters
* f [nm * 3] :
* t [nm * 3] :
* uf [nf * 3] :
* of [nf * 3] :
* OUTPUT
* u [nm * 3] :
* o [nm * 3] :
* ff [nf * 3] :
* tf [nf * 3] :
*/
void
solve_mix_3ft_noHI (struct stokes *sys,
const double *f, const double *t,
const double *uf, const double *of,
double *u, double *o,
double *ff, double *tf)
{
if (sys->version != 1)
{
fprintf (stderr, "libstokes solve_mix_3ft_noHI :"
" the version is wrong. reset to FT\n");
sys->version = 1;
}
int np = sys->np;
int nm = sys->nm;
int i;
// for fixed particles
int nf = np - nm;
if (nf > 0)
{
double *uf0 = (double *) malloc (sizeof (double) * nf * 3);
double *of0 = (double *) malloc (sizeof (double) * nf * 3);
CHECK_MALLOC (uf0, "solve_mix_3ft_noHI");
CHECK_MALLOC (of0, "solve_mix_3ft_noHI");
shift_labo_to_rest_U (sys, nf, uf, uf0);
shift_labo_to_rest_O (sys, nf, of, of0);
/* the main calculation is done in the the fluid-rest frame;
* u(x)=0 as |x|-> infty */
for (i = 0; i < nf * 3; i ++)
{
ff[i] = uf0[i];
tf[i] = of0[i] / 0.75;
}
free (uf0);
free (of0);
}
// for mobile particles
for (i = 0; i < nm * 3; i ++)
{
u[i] = f[i];
o[i] = t[i] * 0.75;
}
/* for the interface, we are in the labo frame, that is
* u(x) is given by the imposed flow field as |x|-> infty */
shift_rest_to_labo_U (sys, nm, u);
shift_rest_to_labo_O (sys, nm, o);
}
示例12: handle_server_failure
int handle_server_failure(struct jsonrpc_server *server)
{
LM_INFO("Setting timer to reconnect to %s on port %d in %d seconds.\n", server->host, server->port, JSONRPC_RECONNECT_INTERVAL);
if (server->socket)
close(server->socket);
server->socket = 0;
if (server->ev != NULL) {
event_del(server->ev);
pkg_free(server->ev);
server->ev = NULL;
}
server->status = JSONRPC_SERVER_FAILURE;
server->conn_attempts--;
if(_jsonrpcc_max_conn_retry!=-1 && server->conn_attempts<0) {
LM_ERR("max reconnect attempts. No further attempts will be made to reconnect this server.");
return -1;
}
int timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
if (timerfd == -1) {
LM_ERR("Could not create timerfd to reschedule connection. No further attempts will be made to reconnect this server.");
return -1;
}
struct itimerspec *itime = pkg_malloc(sizeof(struct itimerspec));
CHECK_MALLOC(itime);
itime->it_interval.tv_sec = 0;
itime->it_interval.tv_nsec = 0;
itime->it_value.tv_sec = JSONRPC_RECONNECT_INTERVAL;
itime->it_value.tv_nsec = 0;
if (timerfd_settime(timerfd, 0, itime, NULL) == -1)
{
LM_ERR("Could not set timer to reschedule connection. No further attempts will be made to reconnect this server.");
return -1;
}
LM_INFO("timerfd value is %d\n", timerfd);
struct event *timer_ev = pkg_malloc(sizeof(struct event));
CHECK_MALLOC(timer_ev);
event_set(timer_ev, timerfd, EV_READ, reconnect_cb, server);
if(event_add(timer_ev, NULL) == -1) {
LM_ERR("event_add failed while rescheduling connection (%s). No further attempts will be made to reconnect this server.", strerror(errno));
return -1;
}
server->ev = timer_ev;
server->timer = itime;
return 0;
}
示例13: solve_gen_linear
/* solve generalized linear set of equations using LU-decomposition
* INPUT
* n1, n2 : dimension
* A [n1 * n1] :
* B [n1 * n2] :
* C [n2 * n1] :
* D [n2 * n2] :
*
* E [n1 * n1] :
* F [n1 * n2] :
* G [n2 * n1] :
* H [n2 * n2] :
* where the generalized linear set of equations is
* [A B](x) = [E F](b)
* [C D](y) [G H](c)
* OUTPUT
* I [n1 * n1] :
* J [n1 * n2] :
* K [n2 * n1] :
* L [n2 * n2] :
* where the generalized linear set of equations is
* (x) = [I J](b)
* (c) [K L](y)
* note that A-D, E-H are destroyed!
*/
void
solve_gen_linear (int n1, int n2,
double * A, double * B, double * C, double * D,
double * E, double * F, double * G, double * H,
double * I, double * J, double * K, double * L)
{
/* H := H^-1 */
lapack_inv_ (n2, H);
/* C := (H^-1) . C */
mul_left_sq (C, n2, n1, H);
/* G := (H^-1) . G */
mul_left_sq (G, n2, n1, H);
/* D := (H^-1) . D */
mul_left_sq (D, n2, n2, H);
double *a = (double *)malloc (sizeof (double) * n1 * n1);
double *e = (double *)malloc (sizeof (double) * n1 * n1);
double *b = (double *)malloc (sizeof (double) * n1 * n2);
CHECK_MALLOC (a, "solve_gen_linear");
CHECK_MALLOC (e, "solve_gen_linear");
CHECK_MALLOC (b, "solve_gen_linear");
/* a [n1, n1] := A - F.(H^-1).C */
add_and_mul (A, n1, n1, F, n1, n2, C, n2, n1, 1.0, -1.0, a);
// e [n1, n1] := E - F.(H^-1).G
add_and_mul (E, n1, n1, F, n1, n2, G, n2, n1, 1.0, -1.0, e);
// b [n1, n2] := - B + F.(H^-1).D
add_and_mul (B, n1, n2, F, n1, n2, D, n2, n2, -1.0, 1.0, b);
/* a := (A-F.(H^-1).C)^-1 */
lapack_inv_ (n1, a);
/* I := a.e */
mul_matrices (a, n1, n1, e, n1, n1, I);
/* J := a.b */
mul_matrices (a, n1, n1, b, n1, n2, J);
free (a);
free (e);
free (b);
// K := - G + C.I
add_and_mul (G, n2, n1, C, n2, n1, I, n1, n1, -1.0, 1.0, K);
// L := D + C.J
add_and_mul (D, n2, n2, C, n2, n1, J, n1, n2, 1.0, 1.0, L);
}
示例14: pv_complex_init
struct pv_complex *
pv_complex_init (long len, long hop_syn, int flag_window)
{
int i;
struct pv_complex * pv
= (struct pv_complex *) malloc (sizeof (struct pv_complex));
CHECK_MALLOC (pv, "pv_complex_init");
pv->len = len;
pv->hop_syn = hop_syn;
pv->flag_window = flag_window;
pv->window_scale = get_scale_factor_for_window (len, hop_syn, flag_window);
pv->time = (double *)fftw_malloc (len * sizeof(double));
pv->freq = (double *)fftw_malloc (len * sizeof(double));
CHECK_MALLOC (pv->time, "pv_complex_init");
CHECK_MALLOC (pv->freq, "pv_complex_init");
pv->plan = fftw_plan_r2r_1d (len, pv->time, pv->freq,
FFTW_R2HC, FFTW_ESTIMATE);
pv->f_out = (double *)fftw_malloc (len * sizeof(double));
pv->t_out = (double *)fftw_malloc (len * sizeof(double));
CHECK_MALLOC (pv->f_out, "pv_complex_init");
CHECK_MALLOC (pv->t_out, "pv_complex_init");
pv->plan_inv = fftw_plan_r2r_1d (len, pv->f_out, pv->t_out,
FFTW_HC2R, FFTW_ESTIMATE);
pv->l_f_old = (double *)malloc (len * sizeof(double));
pv->r_f_old = (double *)malloc (len * sizeof(double));
CHECK_MALLOC (pv->l_f_old, "pv_complex_init");
CHECK_MALLOC (pv->r_f_old, "pv_complex_init");
pv->l_out = (double *) malloc ((hop_syn + len) * sizeof(double));
pv->r_out = (double *) malloc ((hop_syn + len) * sizeof(double));
CHECK_MALLOC (pv->l_out, "pv_complex_init");
CHECK_MALLOC (pv->r_out, "pv_complex_init");
for (i = 0; i < (hop_syn + len); i ++)
{
pv->l_out [i] = 0.0;
pv->r_out [i] = 0.0;
}
pv->flag_left = 0; /* l_f_old[] is not initialized yet */
pv->flag_right = 0; /* r_f_old[] is not initialized yet */
pv->flag_lock = 0; /* no phase lock (for default) */
/*pv->pitch_shift = 0.0; // no pitch-shift */
return (pv);
}
示例15: sndfile_write
long sndfile_write (SNDFILE *sf, SF_INFO sfinfo,
double * left, double * right,
int len)
{
sf_count_t status;
if (sfinfo.channels == 1)
{
status = sf_writef_double (sf, left, (sf_count_t)len);
}
else
{
double *buf = NULL;
buf = (double *) malloc (sizeof (double) * len * sfinfo.channels);
CHECK_MALLOC (buf, "sndfile_write");
int i;
for (i = 0; i < len; i ++)
{
buf [i * sfinfo.channels] = left [i];
buf [i * sfinfo.channels + 1] = right [i];
}
status = sf_writef_double (sf, buf, (sf_count_t)len);
free (buf);
}
return ((long) status);
}