Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
BlaSparseCOO.c
Go to the documentation of this file.
1
14#include <math.h>
15#include <time.h>
16
17#ifdef _OPENMP
18#include <omp.h>
19#endif
20
21#include "fasp.h"
22#include "fasp_functs.h"
23
24/*---------------------------------*/
25/*-- Public Functions --*/
26/*---------------------------------*/
27
43 const INT n,
44 const INT nnz)
45{
46 dCOOmat A;
47
48 A.rowind = (INT *)fasp_mem_calloc(nnz, sizeof(INT));
49 A.colind = (INT *)fasp_mem_calloc(nnz, sizeof(INT));
50 A.val = (REAL *)fasp_mem_calloc(nnz, sizeof(REAL));
51
52 A.row = m; A.col = n; A.nnz = nnz;
53
54 return A;
55}
56
70void fasp_dcoo_alloc (const INT m,
71 const INT n,
72 const INT nnz,
73 dCOOmat *A)
74{
75
76 if ( nnz > 0 ) {
77 A->rowind = (INT *)fasp_mem_calloc(nnz, sizeof(INT));
78 A->colind = (INT *)fasp_mem_calloc(nnz, sizeof(INT));
79 A->val = (REAL*)fasp_mem_calloc(nnz,sizeof(REAL));
80 }
81 else {
82 A->rowind = NULL;
83 A->colind = NULL;
84 A->val = NULL;
85 }
86
87 A->row = m; A->col = n; A->nnz = nnz;
88
89 return;
90}
91
103{
104 if (A==NULL) return;
105
106 fasp_mem_free(A->rowind); A->rowind = NULL;
107 fasp_mem_free(A->colind); A->colind = NULL;
108 fasp_mem_free(A->val); A->val = NULL;
109}
110
125 const INT offset)
126{
127 const INT nnz = A->nnz;
128 INT i, *ai = A->rowind, *aj = A->colind;
129
130 // Variables for OpenMP
131 SHORT nthreads = 1, use_openmp = FALSE;
132 INT myid, mybegin, myend;
133
134#ifdef _OPENMP
135 if (nnz > OPENMP_HOLDS) {
136 use_openmp = TRUE;
137 nthreads = fasp_get_num_threads();
138 }
139#endif
140
141 if (use_openmp) {
142#ifdef _OPENMP
143#pragma omp parallel for private(myid, i, mybegin, myend)
144#endif
145 for (myid=0; myid<nthreads; myid++) {
146 fasp_get_start_end(myid, nthreads, nnz, &mybegin, &myend);
147 for (i=mybegin; i<myend; ++i) {
148 ai[i]+=offset; aj[i]+=offset;
149 }
150 }
151 }
152 else {
153 for (i=0;i<nnz;++i) {
154 ai[i]+=offset; aj[i]+=offset;
155 }
156 }
157}
158
159/*---------------------------------*/
160/*-- End of File --*/
161/*---------------------------------*/
void fasp_mem_free(void *mem)
Free up previous allocated memory body and set pointer to NULL.
Definition: AuxMemory.c:152
void * fasp_mem_calloc(const unsigned int size, const unsigned int type)
Allocate, initiate, and check memory.
Definition: AuxMemory.c:65
void fasp_get_start_end(const INT procid, const INT nprocs, const INT n, INT *start, INT *end)
Assign Load to each thread.
Definition: AuxThreads.c:93
void fasp_dcoo_free(dCOOmat *A)
Free IJ sparse matrix data memory space.
Definition: BlaSparseCOO.c:102
void fasp_dcoo_alloc(const INT m, const INT n, const INT nnz, dCOOmat *A)
Allocate COO sparse matrix memory space.
Definition: BlaSparseCOO.c:70
dCOOmat fasp_dcoo_create(const INT m, const INT n, const INT nnz)
Create IJ sparse matrix data memory space.
Definition: BlaSparseCOO.c:42
void fasp_dcoo_shift(dCOOmat *A, const INT offset)
Re-index a REAL matrix in IJ format to make the index starting from 0 or 1.
Definition: BlaSparseCOO.c:124
Main header file for the FASP project.
#define REAL
Definition: fasp.h:75
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:71
#define INT
Definition: fasp.h:72
#define OPENMP_HOLDS
Definition: fasp_const.h:269
#define TRUE
Definition of logic type.
Definition: fasp_const.h:61
#define FALSE
Definition: fasp_const.h:62
Sparse matrix of REAL type in COO (IJ) format.
Definition: fasp.h:221
INT * colind
integer array of column indices, the size is nnz
Definition: fasp.h:236
INT col
column of matrix A, n
Definition: fasp.h:227
INT * rowind
integer array of row indices, the size is nnz
Definition: fasp.h:233
REAL * val
nonzero entries of A
Definition: fasp.h:239
INT row
row number of matrix A, m
Definition: fasp.h:224
INT nnz
number of nonzero entries
Definition: fasp.h:230