QREngineResultCode GPUQREngine_Cleanup ( QREngineResultCode code, // The result code that we're exiting with Front *userFronts, // The user-provided list of fronts Front *fronts, // The internal copy of the user's fronts Int numFronts, // The number of fronts to be factorized Workspace *wsMongoF, // Pointer to the total GPU Front workspace Workspace *wsMongoR // Pointer to the total CPU R workspace ) { /* Cleanup fronts. */ for(int f=0; f<numFronts; f++) { Front *userFront = (&userFronts[f]); Front *front = &(fronts[f]); if(front != NULL) { /* If we had to attach our own stair, clean it up. */ if(userFront->Stair == NULL && front->Stair != NULL) { front->Stair = (Int *) SuiteSparse_free(front->Stair); } /* Detach front data since it's managed by the mongo. */ front->F = NULL; } } fronts = (Front *) SuiteSparse_free(fronts); /* Free the mongo structures. Note that Workspace checks for NULL. */ wsMongoF = Workspace::destroy(wsMongoF); wsMongoR = Workspace::destroy(wsMongoR); return code; }
GLOBAL void *UMF_free ( void *p ) { DEBUG0 (("UMF_free: "ID"\n", (Int) p)) ; if (p) { SuiteSparse_free (p) ; #if defined (UMF_MALLOC_COUNT) || !defined (NDEBUG) /* One more object has been free'd. Keep track of the count. */ /* (purely for sanity checks). */ UMF_malloc_count-- ; DEBUG0 ((" new malloc count: "ID"\n", UMF_malloc_count)) ; #endif } return ((void *) NULL) ; }
cs *read_matrix(const char *filename, MM_typecode &matcode) { LogInfo("Reading Matrix from " << std::string(filename) << "\n"); FILE *file = fopen(filename, "r"); if (!file) { LogError("Error: Cannot read file " << std::string(filename) << "\n"); return NULL; } LogInfo("Reading Matrix Market banner..."); if (mm_read_banner(file, &matcode) != 0) { LogError("Error: Could not process Matrix Market banner\n"); fclose(file); return NULL; } if (!mm_is_matrix(matcode) || !mm_is_sparse(matcode) || mm_is_complex(matcode)) { LogError( "Error: Unsupported matrix format - Must be real and sparse\n"); fclose(file); return NULL; } Int M, N, nz; if ((mm_read_mtx_crd_size(file, &M, &N, &nz)) != 0) { LogError("Error: Could not parse matrix dimension and size.\n"); fclose(file); return NULL; } if (M != N) { LogError("Error: Matrix must be square.\n"); fclose(file); return NULL; } LogInfo("Reading matrix data...\n"); Int *I = (Int *)SuiteSparse_malloc(static_cast<size_t>(nz), sizeof(Int)); Int *J = (Int *)SuiteSparse_malloc(static_cast<size_t>(nz), sizeof(Int)); double *val = (double *)SuiteSparse_malloc(static_cast<size_t>(nz), sizeof(double)); if (!I || !J || !val) { LogError("Error: Ran out of memory in Mongoose::read_matrix\n"); SuiteSparse_free(I); SuiteSparse_free(J); SuiteSparse_free(val); fclose(file); return NULL; } mm_read_mtx_crd_data(file, M, N, nz, I, J, val, matcode); fclose(file); // Close the file for (Int k = 0; k < nz; k++) { --I[k]; --J[k]; if (mm_is_pattern(matcode)) val[k] = 1; } cs *A = (cs *)SuiteSparse_malloc(1, sizeof(cs)); if (!A) { LogError("Error: Ran out of memory in Mongoose::read_matrix\n"); SuiteSparse_free(I); SuiteSparse_free(J); SuiteSparse_free(val); return NULL; } A->nzmax = nz; A->m = M; A->n = N; A->p = J; A->i = I; A->x = val; A->nz = nz; LogInfo("Compressing matrix from triplet to CSC format...\n"); cs *compressed_A = cs_compress(A); cs_spfree(A); if (!compressed_A) { LogError("Error: Ran out of memory in Mongoose::read_matrix\n"); return NULL; } return compressed_A; }
~Front() { // for the sparse case, F is NULL on the CPU F = (double *) SuiteSparse_free (F) ; }
GLOBAL Int AMD_order ( Int n, const Int Ap [ ], const Int Ai [ ], Int P [ ], double Control [ ], double Info [ ] ) { Int *Len, *S, nz, i, *Pinv, info, status, *Rp, *Ri, *Cp, *Ci, ok ; size_t nzaat, slen ; double mem = 0 ; #ifndef NDEBUG AMD_debug_init ("amd") ; #endif /* clear the Info array, if it exists */ info = Info != (double *) NULL ; if (info) { for (i = 0 ; i < AMD_INFO ; i++) { Info [i] = EMPTY ; } Info [AMD_N] = n ; Info [AMD_STATUS] = AMD_OK ; } /* make sure inputs exist and n is >= 0 */ if (Ai == (Int *) NULL || Ap == (Int *) NULL || P == (Int *) NULL || n < 0) { if (info) Info [AMD_STATUS] = AMD_INVALID ; return (AMD_INVALID) ; /* arguments are invalid */ } if (n == 0) { return (AMD_OK) ; /* n is 0 so there's nothing to do */ } nz = Ap [n] ; if (info) { Info [AMD_NZ] = nz ; } if (nz < 0) { if (info) Info [AMD_STATUS] = AMD_INVALID ; return (AMD_INVALID) ; } /* check if n or nz will cause size_t overflow */ if (((size_t) n) >= SIZE_T_MAX / sizeof (Int) || ((size_t) nz) >= SIZE_T_MAX / sizeof (Int)) { if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ; return (AMD_OUT_OF_MEMORY) ; /* problem too large */ } /* check the input matrix: AMD_OK, AMD_INVALID, or AMD_OK_BUT_JUMBLED */ status = AMD_valid (n, n, Ap, Ai) ; if (status == AMD_INVALID) { if (info) Info [AMD_STATUS] = AMD_INVALID ; return (AMD_INVALID) ; /* matrix is invalid */ } /* allocate two size-n integer workspaces */ Len = SuiteSparse_malloc (n, sizeof (Int)) ; Pinv = SuiteSparse_malloc (n, sizeof (Int)) ; mem += n ; mem += n ; if (!Len || !Pinv) { /* :: out of memory :: */ SuiteSparse_free (Len) ; SuiteSparse_free (Pinv) ; if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ; return (AMD_OUT_OF_MEMORY) ; } if (status == AMD_OK_BUT_JUMBLED) { /* sort the input matrix and remove duplicate entries */ AMD_DEBUG1 (("Matrix is jumbled\n")) ; Rp = SuiteSparse_malloc (n+1, sizeof (Int)) ; Ri = SuiteSparse_malloc (nz, sizeof (Int)) ; mem += (n+1) ; mem += MAX (nz,1) ; if (!Rp || !Ri) { /* :: out of memory :: */ SuiteSparse_free (Rp) ; SuiteSparse_free (Ri) ; SuiteSparse_free (Len) ; SuiteSparse_free (Pinv) ; if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ; return (AMD_OUT_OF_MEMORY) ; } /* use Len and Pinv as workspace to create R = A' */ AMD_preprocess (n, Ap, Ai, Rp, Ri, Len, Pinv) ; Cp = Rp ; Ci = Ri ; } else { /* order the input matrix as-is. No need to compute R = A' first */ Rp = NULL ; Ri = NULL ; Cp = (Int *) Ap ; Ci = (Int *) Ai ; } /* --------------------------------------------------------------------- */ /* determine the symmetry and count off-diagonal nonzeros in A+A' */ /* --------------------------------------------------------------------- */ nzaat = AMD_aat (n, Cp, Ci, Len, P, Info) ; AMD_DEBUG1 (("nzaat: %g\n", (double) nzaat)) ; ASSERT ((MAX (nz-n, 0) <= nzaat) && (nzaat <= 2 * (size_t) nz)) ; /* --------------------------------------------------------------------- */ /* allocate workspace for matrix, elbow room, and 6 size-n vectors */ /* --------------------------------------------------------------------- */ S = NULL ; slen = nzaat ; /* space for matrix */ ok = ((slen + nzaat/5) >= slen) ; /* check for size_t overflow */ slen += nzaat/5 ; /* add elbow room */ for (i = 0 ; ok && i < 7 ; i++) { ok = ((slen + n) > slen) ; /* check for size_t overflow */ slen += n ; /* size-n elbow room, 6 size-n work */ } mem += slen ; ok = ok && (slen < SIZE_T_MAX / sizeof (Int)) ; /* check for overflow */ ok = ok && (slen < Int_MAX) ; /* S[i] for Int i must be OK */ if (ok) { S = SuiteSparse_malloc (slen, sizeof (Int)) ; } AMD_DEBUG1 (("slen %g\n", (double) slen)) ; if (!S) { /* :: out of memory :: (or problem too large) */ SuiteSparse_free (Rp) ; SuiteSparse_free (Ri) ; SuiteSparse_free (Len) ; SuiteSparse_free (Pinv) ; if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ; return (AMD_OUT_OF_MEMORY) ; } if (info) { /* memory usage, in bytes. */ Info [AMD_MEMORY] = mem * sizeof (Int) ; } /* --------------------------------------------------------------------- */ /* order the matrix */ /* --------------------------------------------------------------------- */ AMD_1 (n, Cp, Ci, P, Pinv, Len, slen, S, Control, Info) ; /* --------------------------------------------------------------------- */ /* free the workspace */ /* --------------------------------------------------------------------- */ SuiteSparse_free (Rp) ; SuiteSparse_free (Ri) ; SuiteSparse_free (Len) ; SuiteSparse_free (Pinv) ; SuiteSparse_free (S) ; if (info) Info [AMD_STATUS] = status ; return (status) ; /* successful ordering */ }
int main (int argc, char **argv) { double xr, xz, xmin, xmax ; double *Ax, *Az ; Long nrow, ncol, mkind, skind, *Ap, *Ai, i, *Zp, *Zi, asize, mkind2, skind2, znz, j, p, status, njumbled, nzeros, build_upper, zero_handling, fem, xsize, nelnz, nnz, kk, anz ; int ok ; char title [73], key [9], mtype [4], mtype2 [4], *filename, s [100], *As ; SuiteSparse_config config ; config.malloc_memory = malloc ; config.free_memory = free ; /* test arg-handling for RB functions */ status = RBread (NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) ; if (status != RBIO_ARG_ERROR) { printf ("RBtest failure (1)!\n") ; return (1) ; } status = RBreadraw (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) ; if (status != RBIO_ARG_ERROR) { printf ("RBtest failure (2)\n") ; return (1) ; } status = RBread ("no file", build_upper, zero_handling, title, key, mtype, &nrow, &ncol, &mkind, &skind, &asize, &znz, &Ap, &Ai, &Ax, &Az, &Zp, &Zi, &config) ; if (status != RBIO_FILE_IOERROR) { printf ("RBtest failure (3)\n") ; return (1) ; } status = RBreadraw ("no file", title, key, mtype, &nrow, &ncol, &nnz, &nelnz, &mkind, &skind, &fem, &xsize, &Ap, &Ai, &Ax, NULL) ; if (status != RBIO_FILE_IOERROR) { printf ("RBtest failure (4)\n") ; return (1) ; } status = RBwrite (NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) ; if (status != RBIO_ARG_ERROR) { printf ("RBtest failure (5)\n") ; return (1) ; } status = RBkind (1, 1, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL) ; if (status != RBIO_ARG_ERROR) { printf ("RBtest failure (6)\n") ; return (1) ; } status = RBread ("matrices/m4.rb", 1, 2, title, key, mtype, &nrow, &ncol, &mkind, &skind, &asize, &znz, &Ap, &Ai, &Ax, NULL, &Zp, &Zi, &config) ; if (status != 0) { SuiteSparse_free (Ap, &config) ; SuiteSparse_free (Ai, &config) ; SuiteSparse_free (Ax, &config) ; SuiteSparse_free (Zp, &config) ; SuiteSparse_free (Zi, &config) ; printf ("RBread test failure (7) "ID"\n", status) ; return (1) ; } /* mangle the matrix */ Ap [0] = 1 ; status = RBwrite ("temp.rb", title, key, nrow, ncol, Ap, Ai, Ax, NULL, Zp, Zi, mkind, mtype2, NULL) ; if (status == RBIO_OK) { printf ("RBtest failure (8)\n") ; return (1) ; } Ap [0] = 0 ; Zp [0] = 1 ; status = RBwrite ("temp.rb", title, key, nrow, ncol, Ap, Ai, Ax, NULL, Zp, Zi, mkind, mtype2, NULL) ; if (status == RBIO_OK) { printf ("RBtest failure (9)\n") ; return (1) ; } Zp [0] = 0 ; /* valid matrix */ status = RBwrite ("temp.rb", title, key, nrow, ncol, Ap, Ai, Ax, NULL, Zp, Zi, mkind, NULL, NULL) ; if (status != RBIO_OK) { printf ("RBtest failure (10) "ID"\n", status) ; return (1) ; } /* valid matrix, different integer formats */ Ax [0] = 1e5 ; for (kk = 0 ; kk < 10 ; kk++) { sprintf (s, "temp_" ID ".rb", kk) ; status = RBwrite (s, title, key, nrow, ncol, Ap, Ai, Ax, NULL, Zp, Zi, mkind, NULL, NULL) ; if (status != RBIO_OK) { printf ("RBtest failure (11) "ID" "ID"\n", status, kk) ; return (1) ; } Ax [0] *= 10 ; } /* valid matrix, but with a very large integer */ Ax [0] = 1e9 + 1 ; status = RBwrite ("temp1.rb", title, key, nrow, ncol, Ap, Ai, Ax, NULL, Zp, Zi, mkind, NULL, NULL) ; if (status != RBIO_OK) { printf ("RBtest failure (12) "ID"\n", status) ; return (1) ; } /* valid matrix, but with a very large real */ Ax [0] = 1e100 ; status = RBwrite ("temp2.rb", title, key, nrow, ncol, Ap, Ai, Ax, NULL, Zp, Zi, mkind, NULL, NULL) ; if (status != RBIO_OK) { printf ("RBtest failure (13) "ID"\n", status) ; return (1) ; } /* valid matrix, but with a Z that overlaps A */ Ax [0] = 1 ; Zi [0] = 1 ; status = RBwrite ("temp3.rb", title, key, nrow, ncol, Ap, Ai, Ax, NULL, Zp, Zi, mkind, NULL, NULL) ; if (status != RBIO_OK) { printf ("RBtest failure (14) "ID"\n", status) ; return (1) ; } /* invalid file name */ status = RBwrite ("gunk/gunk.rb", title, key, nrow, ncol, Ap, Ai, Ax, NULL, Zp, Zi, mkind, NULL, NULL) ; if (status != RBIO_FILE_IOERROR) { printf ("RBtest failure (12) "ID"\n", status) ; return (1) ; } /* cannot write a matrix with no entries */ for (j = 0 ; j <= ncol ; j++) { Ap [j] = 0 ; Zp [j] = 0 ; } status = RBwrite ("temp.rb", title, key, nrow, ncol, Ap, Ai, Ax, NULL, Zp, Zi, mkind, NULL, NULL) ; if (status != RBIO_DIM_INVALID) { printf ("RBtest failure (13) "ID"\n", status) ; return (1) ; } SuiteSparse_free (Ap, &config) ; SuiteSparse_free (Ai, &config) ; SuiteSparse_free (Ax, &config) ; SuiteSparse_free (Zp, &config) ; SuiteSparse_free (Zi, &config) ; /* re-read a valid matrix */ status = RBread ("matrices/m4.rb", 1, 0, title, key, mtype, &nrow, &ncol, &mkind, &skind, &asize, &znz, &Ap, &Ai, &Ax, NULL, NULL, NULL, &config) ; if (status != 0) { SuiteSparse_free (Ap, &config) ; SuiteSparse_free (Ai, &config) ; SuiteSparse_free (Ax, &config) ; SuiteSparse_free (Zp, &config) ; SuiteSparse_free (Zi, &config) ; printf ("RBread test failure (14) "ID"\n", status) ; return (1) ; } status = RBok (nrow, ncol, asize, Ap, Ai, Ax, Az, NULL, mkind, &njumbled, &nzeros) ; if (status != RBIO_OK) { printf ("RBread test failure (15) "ID"\n", status) ; } status = RBok (nrow, ncol, asize, Ap, Ai, Ax, Az, NULL, -1, &njumbled, &nzeros) ; if (status != RBIO_MKIND_INVALID) { printf ("RBread test failure (16) "ID"\n", status) ; } status = RBok (-1, ncol, asize, Ap, Ai, Ax, Az, NULL, mkind, &njumbled, &nzeros) ; if (status != RBIO_DIM_INVALID) { printf ("RBread test failure (17) "ID"\n", status) ; } i = Ap [1] ; Ap [1] = 999999 ; status = RBok (nrow, ncol, asize, Ap, Ai, Ax, Az, NULL, mkind, &njumbled, &nzeros) ; if (status != RBIO_CP_INVALID) { printf ("RBread test failure (18) "ID"\n", status) ; } Ap [1] = i ; status = RBok (nrow, ncol, asize, Ap, NULL, Ax, Az, NULL, mkind, &njumbled, &nzeros) ; if (status != RBIO_ROW_INVALID) { printf ("RBread test failure (19) "ID"\n", status) ; } i = Ai [0] ; Ai [0] = 999999 ; status = RBok (nrow, ncol, asize, Ap, Ai, Ax, Az, NULL, mkind, &njumbled, &nzeros) ; if (status != RBIO_ROW_INVALID) { printf ("RBread test failure (20) "ID"\n", status) ; } Ai [0] = i ; i = Ai [1] ; Ai [1] = Ai [0] ; status = RBok (nrow, ncol, asize, Ap, Ai, Ax, Az, NULL, mkind, &njumbled, &nzeros) ; if (status != RBIO_JUMBLED) { printf ("RBread test failure (21) "ID"\n", status) ; } Ai [1] = i ; ok = 1 ; As = (char *) SuiteSparse_malloc (asize, sizeof (char), &ok, &config) ; for (i = 0 ; i < asize ; i++) As [i] = 1 ; status = RBok (nrow, ncol, asize, Ap, Ai, Ax, Az, As, 1, &njumbled, &nzeros) ; if (status != RBIO_OK) { printf ("RBread test failure (22) "ID"\n", status) ; } SuiteSparse_free (As, &config) ; printf ("RBtest OK\n") ; return (0) ; }
EdgeCutProblem::~EdgeCutProblem() { p = (shallow_p) ? NULL : (Int *)SuiteSparse_free(p); i = (shallow_i) ? NULL : (Int *)SuiteSparse_free(i); x = (shallow_x) ? NULL : (double *)SuiteSparse_free(x); w = (shallow_w) ? NULL : (double *)SuiteSparse_free(w); partition = (bool *)SuiteSparse_free(partition); vertexGains = (double *)SuiteSparse_free(vertexGains); externalDegree = (Int *)SuiteSparse_free(externalDegree); bhIndex = (Int *)SuiteSparse_free(bhIndex); bhHeap[0] = (Int *)SuiteSparse_free(bhHeap[0]); bhHeap[1] = (Int *)SuiteSparse_free(bhHeap[1]); matching = (Int *)SuiteSparse_free(matching); matchmap = (Int *)SuiteSparse_free(matchmap); invmatchmap = (Int *)SuiteSparse_free(invmatchmap); matchtype = (Int *)SuiteSparse_free(matchtype); markArray = (Int *)SuiteSparse_free(markArray); SuiteSparse_free(this); }