MCPcopy Create free account
hub / github.com/pydata/numexpr / reinit_threads

Function reinit_threads

numexpr3/module.cpp:164–206  ·  view source on GitHub ↗

Initialize threads and allocate space for arrays in global_state

Source from the content-addressed store, hash-verified

162
163// Initialize threads and allocate space for arrays in global_state
164int reinit_threads(int n_thread_old) {
165 int tid, rc;
166
167 gs.count_threads = 0; // Reset threads counter
168 gs.barrier_passed = BARRIER_HALT;
169
170 // Allocate memory
171 gs.threads = (pthread_t*)realloc( gs.threads, gs.n_thread * sizeof(pthread_t) );
172 gs.tids = (int*)realloc( gs.tids, gs.n_thread * sizeof(int*) );
173
174 gs.params = (NumExprObject*)realloc( gs.params, gs.n_thread * sizeof(NumExprObject) );
175 // params[R].program is shared.
176
177 // Allocate an arena for the registers
178 // Since NPY_MAXARGS=32, we can just allocate a maximum space and only
179 // consume a kB or so of RAM.
180 gs.registerArena = (char *)realloc( gs.registerArena, gs.n_thread * NPY_MAXARGS * sizeof(NumExprReg) );
181 for( int I=0; I < gs.n_thread; I++ ) {
182 gs.params[I].registers = (NumExprReg*)(gs.registerArena + I*NPY_MAXARGS*sizeof(NumExprReg) );
183 }
184
185 gs.stridesArray = (npy_intp*)realloc( gs.stridesArray, gs.n_thread * sizeof(npy_intp) );
186 gs.iter = (NpyIter**)realloc( gs.iter, gs.n_thread * sizeof(NpyIter*) );
187 gs.reduce_iter = (NpyIter**)realloc( gs.reduce_iter, gs.n_thread * sizeof(NpyIter*) );
188
189 // Finally, create the threads
190 for (tid = 0; tid < gs.n_thread; tid++) {
191 gs.tids[tid] = tid;
192 rc = pthread_create(&gs.threads[tid], NULL, th_worker, (void *)&gs.tids[tid]);
193
194 if (rc) {
195 fprintf(stderr,
196 "ERROR; return code from pthread_create() is %d\n", rc);
197 fprintf(stderr, "\tError detail: %s\n", strerror(rc));
198 exit(-1);
199 }
200 }
201
202 gs.init_threads_done = 1; // Initialization done!
203 gs.pid = (int)getpid(); // save the PID for this process
204
205 return(0);
206}
207
208
209int numexpr_set_nthreads(int n_thread_new) {

Callers 1

numexpr_set_nthreadsFunction · 0.85

Calls 1

pthread_createFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…