F
F
footballer2018-03-28 19:10:57
Multithreading
footballer, 2018-03-28 19:10:57

Is there an advantage to running a task on two threads on the same core?

Given: there is a task consisting of two unrelated subtasks. There is a single-core processor. And 2 options for solving the problem:
1) write a program (one function) that first solves subtask 1, and then subtask 2, one after the other sequentially in one thread.
2) write a program of two functions, each function will solve its own subtask, and call these functions at the same time, that is, by creating a separate thread for each and starting parallel execution.
Question: in what case will the entire task (both subtasks) be completed faster?
UPDATE: additional questions:
1) professorweb.ru/my/csharp/thread_and_files/1/1_16.php

The value of the maximum allowed number of threads in the pool can change. For a dual-core CPU, it defaults to 1023 worker threads and 1000 I/O threads.

Why on a dual-core 2023 thread?
2) regfordev.blogspot.ru/2010/12/thread-pool.html
As more cores are added, tasks begin to break into smaller pieces. Accordingly, worker threads often turn to the global queue, the load on which is clearly increasing - the lock makes itself felt.

Increasing the number of cores in the system is similar to increasing the number of participants, since tasks will be divided into smaller pieces and, due to frequent access to the global queue, the need for synchronization will increase.

I didn’t understand, “With the addition of more cores, tasks begin to be divided into smaller pieces” - how is that? Here I have a task that my program performs in one thread. If I run my program on a multi-core processor, will my task be divided into many pieces? How? She's single-handed.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Roman Mirilaczvili, 2018-03-28
@2ord

In my opinion, the 1st option will be faster, since no time will be spent on context switching. So there may not be an advantage when it comes to some abstract computational problem. But in practice, acceleration can be when there is work with a network or data storage devices.
This is my guess.

A
Alexander Yudakov, 2018-03-28
@AlexanderYudakov

The number of nuances that can affect the result in your particular case is so large that it is cheaper to write two options, measure and compare.
The main postulate in the work on improving productivity: MOM - measure, optimize, monitor.

N
nowm, 2014-01-14
@last7

In general, "(.+)(?P< volume>\d+)?(\s?pcs)?$" to pull out a number is overkill. Why such a complex expression?

m = re.search('(\d+)[\s]?шт', 'Коробка шт с кирпичами 10 шт;')
m.group(1)

Edit: a more specific regular expression that does not respond to words like: "plaster", "rod" and others that begin with "pc »: (\d+)[\s]?pcs([^a-zA-z]|$)

R
rhaport, 2014-01-14
@rhaport

r = re.compile('(?P<volume>\d+)\sшт([^А-Яа-я]|$)')
r.search("bla bla 10 шт").group("volume")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question