Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
AuxThreads.c
Go to the documentation of this file.
1
13#include <stdio.h>
14#include <stdlib.h>
15
16#ifdef _OPENMP
17#include <omp.h>
18#endif
19
20#include "fasp.h"
21#include "fasp_functs.h"
22
23/*---------------------------------*/
24/*-- Public Functions --*/
25/*---------------------------------*/
26
27#ifdef _OPENMP
28
29INT thread_ini_flag = 0;
30
41INT fasp_get_num_threads ( void )
42{
43 static INT nthreads;
44
45 if ( thread_ini_flag == 0 ) {
46 nthreads = 1;
47#pragma omp parallel
48 nthreads = omp_get_num_threads();
49
50 printf("\nFASP is running on %d thread(s).\n\n", nthreads);
51 thread_ini_flag = 1;
52 }
53
54 return nthreads;
55}
56
69INT fasp_set_num_threads (const INT nthreads)
70{
71 omp_set_num_threads( nthreads );
72
73 return nthreads;
74}
75
76#endif
77
93void fasp_get_start_end (const INT procid,
94 const INT nprocs,
95 const INT n,
96 INT *start,
97 INT *end)
98{
99 INT chunk_size = n / nprocs;
100 INT mod = n % nprocs;
101 INT start_loc, end_loc;
102
103 if ( procid < mod) {
104 end_loc = chunk_size + 1;
105 start_loc = end_loc * procid;
106 }
107 else {
108 end_loc = chunk_size;
109 start_loc = end_loc * procid + mod;
110 }
111 end_loc = end_loc + start_loc;
112
113 *start = start_loc;
114 *end = end_loc;
115}
116
133void fasp_set_gs_threads (const INT mythreads,
134 const INT its)
135{
136#ifdef _OPENMP
137
138#if 1
139
140 if (its <=8) {
141 THDs_AMG_GS = mythreads;
142 THDs_CPR_lGS = mythreads ;
143 THDs_CPR_gGS = mythreads ;
144 }
145 else if (its <=12) {
146 THDs_AMG_GS = mythreads;
147 THDs_CPR_lGS = (6 < mythreads) ? 6 : mythreads;
148 THDs_CPR_gGS = (4 < mythreads) ? 4 : mythreads;
149 }
150 else if (its <=15) {
151 THDs_AMG_GS = (3 < mythreads) ? 3 : mythreads;
152 THDs_CPR_lGS = (3 < mythreads) ? 3 : mythreads;
153 THDs_CPR_gGS = (2 < mythreads) ? 2 : mythreads;
154 }
155 else if (its <=18) {
156 THDs_AMG_GS = (2 < mythreads) ? 2 : mythreads;
157 THDs_CPR_lGS = (2 < mythreads) ? 2 : mythreads;
158 THDs_CPR_gGS = (1 < mythreads) ? 1 : mythreads;
159 }
160 else {
161 THDs_AMG_GS = 1;
162 THDs_CPR_lGS = 1;
163 THDs_CPR_gGS = 1;
164 }
165
166#else
167
168 THDs_AMG_GS = mythreads;
169 THDs_CPR_lGS = mythreads ;
170 THDs_CPR_gGS = mythreads ;
171
172#endif
173
174#endif // _OPENMP
175}
176
177/*---------------------------------*/
178/*-- End of File --*/
179/*---------------------------------*/
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
INT THDs_CPR_gGS
Definition: AuxThreads.c:119
void fasp_set_gs_threads(const INT mythreads, const INT its)
Set threads for CPR. Please add it at the begin of Krylov OpenMP method function and after iter++.
Definition: AuxThreads.c:133
INT THDs_CPR_lGS
Definition: AuxThreads.c:118
INT THDs_AMG_GS
Definition: AuxThreads.c:117
Main header file for the FASP project.
#define INT
Definition: fasp.h:72