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

Function vm_engine_iter_parallel

numexpr3/interpreter.cpp:342–393  ·  view source on GitHub ↗

Parallel iterator version of VM engine This function fills out the global state and then unlocks the mutexes used to control the threads in module.cpp::th_worker prepareThreads() must be called beforehand (or else `self` could not be const).

Source from the content-addressed store, hash-verified

340// used to control the threads in module.cpp::th_worker
341// prepareThreads() must be called beforehand (or else `self` could not be const).
342static int
343vm_engine_iter_parallel(NpyIter *iter, const NumExprObject *self,
344 bool need_output_buffering, int *pc_error,
345 char **errorMessage)
346{
347 if (errorMessage == NULL) return -1;
348
349 // Threads are prepared for execution in prepareThreads()
350 BENCH_TIME(8);
351 Py_BEGIN_ALLOW_THREADS;
352 DIFF_TIME(8);
353
354 BENCH_TIME(4);
355 // Synchronization point for all threads (wait for initialization)
356 pthread_mutex_lock(&gs.count_threads_mutex);
357 BENCH_RANGE(150, gs.n_thread);
358 if (gs.count_threads < gs.n_thread) {
359 gs.count_threads++;
360 // printf( "Main thread init %d\n", gs.count_threads );
361 do {
362 pthread_cond_wait(&gs.count_threads_cv, &gs.count_threads_mutex);
363 } while (gs.barrier_passed == BARRIER_HALT);
364 }
365 else {
366 gs.barrier_passed = BARRIER_PASS;
367 pthread_cond_broadcast(&gs.count_threads_cv);
368 }
369 pthread_mutex_unlock(&gs.count_threads_mutex);
370 DIFF_TIME(4);
371 BENCH_TIME(5);
372 // Synchronization point for all threads (wait for finalization)
373 pthread_mutex_lock(&gs.count_threads_mutex);
374 if (gs.count_threads > 0) {
375 gs.count_threads--;
376 // printf( "Main thread finalize %d\n", gs.count_threads );
377 do {
378 pthread_cond_wait(&gs.count_threads_cv, &gs.count_threads_mutex);
379 } while (gs.barrier_passed == BARRIER_PASS);
380 }
381 else {
382 gs.barrier_passed = BARRIER_HALT;
383 pthread_cond_broadcast(&gs.count_threads_cv);
384 }
385 pthread_mutex_unlock(&gs.count_threads_mutex);
386 DIFF_TIME(5);
387
388 BENCH_TIME(9);
389 Py_END_ALLOW_THREADS;
390 DIFF_TIME(9);
391
392 return gs.ret_code;
393}
394
395static int
396run_interpreter(NumExprObject *self, NpyIter *iter, NpyIter *reduce_iter,

Callers 1

run_interpreterFunction · 0.85

Calls 2

pthread_cond_waitFunction · 0.85
pthread_cond_broadcastFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…