Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
array.c
Go to the documentation of this file.
1 
6 #include <math.h>
7 
8 #ifdef _OPENMP
9 #include <omp.h>
10 #endif
11 
12 #include "fasp.h"
13 #include "fasp_functs.h"
14 
15 /*---------------------------------*/
16 /*-- Public Functions --*/
17 /*---------------------------------*/
18 
30 {
31  x = NULL;
32 }
33 
48 void fasp_array_set (const INT n,
49  REAL *x,
50  const REAL val)
51 {
52  INT i;
53  INT nthreads = 1, use_openmp = FALSE;
54 
55 #ifdef _OPENMP
56  if ( n > OPENMP_HOLDS ) {
57  use_openmp = TRUE;
58  nthreads = FASP_GET_NUM_THREADS();
59  }
60 #endif
61 
62  if (val == 0.0) {
63  if (use_openmp) {
64  INT mybegin,myend,myid;
65 #ifdef _OPENMP
66 #pragma omp parallel for private(myid,mybegin,myend)
67 #endif
68  for (myid = 0; myid < nthreads; myid ++) {
69  FASP_GET_START_END(myid, nthreads, n, &mybegin, &myend);
70  memset(&x[mybegin], 0x0, sizeof(REAL)*(myend-mybegin));
71  }
72  }
73  else
74  memset(x, 0x0, sizeof(REAL)*n);
75  }
76  else {
77  if (use_openmp) {
78  INT mybegin,myend,myid;
79 #ifdef _OPENMP
80 #pragma omp parallel for private(myid,mybegin,myend,i)
81 #endif
82  for (myid = 0; myid < nthreads; myid ++) {
83  FASP_GET_START_END(myid, nthreads, n, &mybegin, &myend);
84  for (i=mybegin; i<myend; ++i) x[i]=val;
85  }
86  }
87  else {
88  for (i=0; i<n; ++i) x[i] = val;
89  }
90  }
91 }
92 
107 void fasp_iarray_set (const INT n,
108  INT *x,
109  const INT val)
110 {
111  INT i;
112  INT nthreads = 1, use_openmp = FALSE;
113 
114 #ifdef _OPENMP
115  if ( n > OPENMP_HOLDS ) {
116  use_openmp = TRUE;
117  nthreads = FASP_GET_NUM_THREADS();
118  }
119 #endif
120 
121  if (val == 0) {
122  if (use_openmp) {
123  INT mybegin,myend,myid;
124 #ifdef _OPENMP
125 #pragma omp parallel for private(myid, mybegin, myend)
126 #endif
127  for (myid = 0; myid < nthreads; myid ++) {
128  FASP_GET_START_END(myid, nthreads, n, &mybegin, &myend);
129  memset(&x[mybegin], 0, sizeof(INT)*(myend-mybegin));
130  }
131  }
132  else {
133  memset(x, 0, sizeof(INT)*n);
134  }
135  }
136  else {
137  if (use_openmp) {
138  INT mybegin,myend,myid;
139 #ifdef _OPENMP
140 #pragma omp parallel for private(myid, mybegin, myend,i)
141 #endif
142  for (myid = 0; myid < nthreads; myid ++) {
143  FASP_GET_START_END(myid, nthreads, n, &mybegin, &myend);
144  for (i=mybegin; i<myend; ++i) x[i]=val;
145  }
146  }
147  else {
148  for (i=0; i<n; ++i) x[i]=val;
149  }
150  }
151 }
152 
165 void fasp_array_cp (const INT n,
166  REAL *x,
167  REAL *y)
168 {
169  memcpy(y, x, n*sizeof(REAL));
170 }
171 
172 
185 void fasp_iarray_cp (const INT n,
186  INT *x,
187  INT *y)
188 {
189  memcpy(y, x, n*sizeof(INT));
190 }
191 
206  REAL *y)
207 {
208  y[0] = x[0];
209  y[1] = x[1];
210  y[2] = x[2];
211 }
212 
227  REAL *y)
228 {
229  y[0] = x[0];
230  y[1] = x[1];
231  y[2] = x[2];
232  y[3] = x[3];
233  y[4] = x[4];
234 }
235 
250  REAL *y)
251 {
252  y[0] = x[0];
253  y[1] = x[1];
254  y[2] = x[2];
255  y[3] = x[3];
256  y[4] = x[4];
257  y[5] = x[5];
258  y[6] = x[6];
259 }
260 
261 /*---------------------------------*/
262 /*-- End of File --*/
263 /*---------------------------------*/
264 
#define TRUE
Definition of logic type.
Definition: fasp_const.h:67
#define REAL
Definition: fasp.h:67
void fasp_array_cp_nc3(REAL *x, REAL *y)
Copy an array to the other y=x, the length is 3.
Definition: array.c:205
void fasp_array_cp_nc5(REAL *x, REAL *y)
Copy an array to the other y=x, the length is 5.
Definition: array.c:226
void fasp_array_null(REAL *x)
Initialize an array.
Definition: array.c:29
#define INT
Definition: fasp.h:64
void FASP_GET_START_END(INT procid, INT nprocs, INT n, INT *start, INT *end)
Assign Load to each thread.
Definition: threads.c:83
void fasp_array_set(const INT n, REAL *x, const REAL val)
Set initial value for an array to be x=val.
Definition: array.c:48
void fasp_iarray_cp(const INT n, INT *x, INT *y)
Copy an array to the other y=x.
Definition: array.c:185
#define OPENMP_HOLDS
Definition: fasp_const.h:248
Main header file for FASP.
void fasp_array_cp_nc7(REAL *x, REAL *y)
Copy an array to the other y=x, the length is 7.
Definition: array.c:249
void fasp_array_cp(const INT n, REAL *x, REAL *y)
Copy an array to the other y=x.
Definition: array.c:165
#define FALSE
Definition: fasp_const.h:68
void fasp_iarray_set(const INT n, INT *x, const INT val)
Set initial value for an array to be x=val.
Definition: array.c:107