1

I am trying to rewrite a few C OMP programs in Python for demonstration purposes. However, I cannot translate the loop scheduler one can find in C (example below)

pragma omp parallel for schedule(static)
for(i=0; i<10; i++)
    printf("\n Process = %d, i = %d", omp_get_thread_num(),i);

Specifically, I need to demonstrate the differences between a dynamic and a static scheduler.

Is there such a thing as a thread scheduler in Python?

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Nick Gkloumpos
  • 113
  • 2
  • 8

1 Answers1

1

There's a dynamic thread scheduler in standard library - concurrent.futures.thread.ThreadPoolExecutor. I don't think that Python can do static compile-time scheduling. Python does very little at compile time, if you can even say compile-time about a language which is mostly interpreted.

Static scheduling would also make little sense, because of GIL (Global Interpreter Lock).

In theory this could be done by exposing bindings to some C library or using other flavours of Python than CPython, but imo Python is just not made for this kind of stuff :P. See this answer.

RafalS
  • 4,726
  • 17
  • 21