MCPcopy Create free account
hub / github.com/boutproject/BOUT-dev / SpgmrMalloc

Function SpgmrMalloc

externalpackages/PVODE/source/spgmr.cpp:37–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35/*************** SpgmrMalloc *****************************************/
36
37SpgmrMem SpgmrMalloc(integer N, int l_max, void *machEnv)
38{
39 SpgmrMem mem;
40 N_Vector *V, xcor, vtemp;
41 real **Hes, *givens, *yg;
42 int k, i;
43
44 /* Check the input parameters */
45
46 if ((N <= 0) || (l_max <= 0)) return(NULL);
47
48 /* Get memory for the Krylov basis vectors V[0], ..., V[l_max] */
49
50 V = (N_Vector *) malloc((l_max+1)*sizeof(N_Vector));
51 if (V == NULL) return(NULL);
52
53 for (k=0; k <= l_max; k++) {
54 V[k] = N_VNew(N, (machEnvType)machEnv);
55 if (V[k] == NULL) {
56 FreeVectorArray(V, k-1);
57 return(NULL);
58 }
59 }
60
61 /* Get memory for the Hessenberg matrix Hes */
62
63 Hes = (real **) malloc((l_max+1)*sizeof(real *));
64 if (Hes == NULL) {
65 FreeVectorArray(V, l_max);
66 return(NULL);
67 }
68
69 for (k=0; k <= l_max; k++) {
70 Hes[k] = (real *) malloc(l_max*sizeof(real));
71 if (Hes[k] == NULL) {
72 for (i=0; i < k; i++) free(Hes[i]);
73 FreeVectorArray(V, l_max);
74 return(NULL);
75 }
76 }
77
78 /* Get memory for Givens rotation components */
79
80 givens = (real *) malloc(2*l_max*sizeof(real));
81 if (givens == NULL) {
82 for (i=0; i <= l_max; i++) free(Hes[i]);
83 FreeVectorArray(V, l_max);
84 return(NULL);
85 }
86
87 /* Get memory to hold the correction to z_tilde */
88
89 xcor = N_VNew(N, (machEnvType)machEnv);
90 if (xcor == NULL) {
91 free(givens);
92 for (i=0; i <= l_max; i++) free(Hes[i]);
93 FreeVectorArray(V, l_max);
94 return(NULL);

Callers 1

CVSpgmrInitFunction · 0.85

Calls 3

N_VNewFunction · 0.85
FreeVectorArrayFunction · 0.85
N_VFreeFunction · 0.85

Tested by

no test coverage detected