Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
threads.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #ifdef _OPENMP
10 #include <omp.h>
11 #endif
12 
13 #include "fasp.h"
14 
15 /*---------------------------------*/
16 /*-- Public Functions --*/
17 /*---------------------------------*/
18 
19 #ifdef _OPENMP
20 
21 INT thread_ini_flag = 0;
22 
33 INT FASP_GET_NUM_THREADS ()
34 {
35  static INT nthreads;
36 
37  if ( thread_ini_flag == 0 ) {
38 #pragma omp parallel
39  nthreads = omp_get_num_threads();
40 
41  printf("\nFASP is running on %3d thread(s).\n\n",nthreads);
42  thread_ini_flag = 1;
43  }
44 
45  return nthreads;
46 }
47 
60 INT Fasp_Set_Num_Threads (INT nthreads)
61 {
62  omp_set_num_threads( nthreads );
63 
64  return nthreads;
65 }
66 
67 #endif
68 
83 void FASP_GET_START_END (INT procid,
84  INT nprocs,
85  INT n,
86  INT *start,
87  INT *end)
88 {
89  INT chunk_size = n / nprocs;
90  INT mod = n % nprocs;
91  INT start_loc, end_loc;
92 
93  if ( procid < mod) {
94  end_loc = chunk_size + 1;
95  start_loc = end_loc * procid;
96  }
97  else {
98  end_loc = chunk_size;
99  start_loc = end_loc * procid + mod;
100  }
101  end_loc = end_loc + start_loc;
102 
103  *start = start_loc;
104  *end = end_loc;
105 }
106 
125 void fasp_set_GS_threads (INT mythreads,
126  INT its)
127 {
128 #ifdef _OPENMP
129 
130 #if 1
131 
132  if (its <=8) {
133  THDs_AMG_GS = mythreads;
134  THDs_CPR_lGS = mythreads ;
135  THDs_CPR_gGS = mythreads ;
136  }
137  else if (its <=12) {
138  THDs_AMG_GS = mythreads;
139  THDs_CPR_lGS = (6 < mythreads) ? 6 : mythreads;
140  THDs_CPR_gGS = (4 < mythreads) ? 4 : mythreads;
141  }
142  else if (its <=15) {
143  THDs_AMG_GS = (3 < mythreads) ? 3 : mythreads;
144  THDs_CPR_lGS = (3 < mythreads) ? 3 : mythreads;
145  THDs_CPR_gGS = (2 < mythreads) ? 2 : mythreads;
146  }
147  else if (its <=18) {
148  THDs_AMG_GS = (2 < mythreads) ? 2 : mythreads;
149  THDs_CPR_lGS = (2 < mythreads) ? 2 : mythreads;
150  THDs_CPR_gGS = (1 < mythreads) ? 1 : mythreads;
151  }
152  else {
153  THDs_AMG_GS = 1;
154  THDs_CPR_lGS = 1;
155  THDs_CPR_gGS = 1;
156  }
157 
158 #else
159 
160  THDs_AMG_GS = mythreads;
161  THDs_CPR_lGS = mythreads ;
162  THDs_CPR_gGS = mythreads ;
163 
164 #endif
165 
166 #endif // _OPENMP
167 }
168 
169 /*---------------------------------*/
170 /*-- End of File --*/
171 /*---------------------------------*/
#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_set_GS_threads(INT mythreads, INT its)
Set threads for CPR. Please add it at the begin of Krylov OpenMP method function and after iter++...
Definition: threads.c:125
INT THDs_AMG_GS
Definition: threads.c:107
INT THDs_CPR_gGS
Definition: threads.c:109
Main header file for FASP.
INT THDs_CPR_lGS
Definition: threads.c:108