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