Multiprocessor execution

0

I'm researching about parallel execution in Python and I was left with a question that I have not found a clear answer yet.

Let's say I want to multiply two arrays and add in a task list where each task is a row of array A and a column of array B and ask that% of threads remove from this list one task to multiply.

I have 4 colors on the machine, using the n module of Python, if I create 4 theads to execute the task list, those threads will be executed one in each core ? That is, in parallel? Or would I need to use the threading.Thread module that divides tasks into 1 process for each core ?

If only with multiprocessing I can distribute the tasks in 4 colors , how do I define 2 threads in each process, ie each > core would receive 2 threads to process my task?

    
asked by anonymous 03.11.2017 / 13:52

1 answer

1

The thread exists to allow concurrent processing. There are no guarantees that the execution will be done on different processors. It is guaranteed that if you only have the main thread it will only run on one processor. That said, you are likely to use all of the available processors if you have at least one thread for each of them. In this case everything will run in parallel.

This is actually the best way to create a thread . I do not like its use when in fact you just want to run asynchronously.

In general you do not have control where it will run, at most you can establish affinity and priority, but I do not know if it has API that deals with this. Have to process .

I do not know how to tinker with threads in Python. I remember having a problem with GIL . I do not understand all the consequences of this.

Some people prefer to do this on another level, in C for example. Must have a reason.

If you're going to be able to parallelize properly, that's another question.

See this to help you make a decision: It is always guaranteed that a multi-threaded application runs faster than using a single thread?

    
03.11.2017 / 14:09