1

I am trying run a total of 8 threads on 4 cores.

I bind the threads in sets of 2 to each of the core by setting the affinity.

0,1 -> core A
2,3 -> core B
4,5 -> core C
6,7 -> core D

I am able to poll the threads to check if they are running. I am also able to collect the time at which it (s)tarted, (e)nd and the time at which (p)erformnace events are collected precisely. I know which of the two threads in the set is dead(by dead, i mean, the execution time is over). There can be cases where the thread 0 or thread 1 is longer than one another.

In either of the cases, i.e, when thread 0 or thread 1 is longer, I want to reiterate the shorter thread till the end of the bigger thread.

Previously, when I had just two threads per core on the overall system. I used to do a manual check like.. if either of the thread is dead.. keep running it till the point where the other is also dead.

But this comes with a lot of redundancy and loss of efficiency(because I was using IF statements)

If I want to scale it for two threads/ more than two threads per core, when each of the cores have a two/ more than two. How can we that?

I need ideas so that we can discuss on that.

this is what I got: As an example take "ted" and "talks" and as two threads on Core A. Assuming ted is shorter of the two threads. the data we have: Time at which it starts, ends, and data collection time. We can calculate the time difference between end-start of the thread ted and the thread talks.

TED_TIME_DIFF = 100ms

but the time period of thread talks keeps on increasing(checking from the calulation of collected times(c)). Assuming the collection time is 1ms for example it can TALKS_TIME_DIFF = 110ms next ms it is 111ms.. etc.

we can keep reiterating ted till talks time diff is stagnent.

Scripting language: Python 2.7
OS: Linux
Kernel:2.6.xx
using SPEC CPU BENCHMARK threads - if that is any importance

would be glad if you can help me out.

6
  • This question is really really rambly. Could you consider editing it down to focus on your current problem and a specific question (like what you're trying to achieve) instead of veering off into mentioning XOR and FLAGS. (I've honestly no idea what you mean by that.) Commented Jan 22, 2013 at 1:02
  • Also, the GIL notwithstanding, in your case I'd change the architecture to use a pool of worker threads that work through a queue of tasks. That way all your threads stay on whichever core they are, and can all be taken down when the queue is empty and no more tasks are incoming. Commented Jan 22, 2013 at 1:04
  • @millimoose: Could you please explain a little more about the last comment? Commented Jan 22, 2013 at 1:05
  • @mish Basically, instead of a thread directly containing the code it needs to execute, use a thread-safe queue of Task objects that encapsulate this code. Each thread will loop, consume one Task from the queue, and execute it. They should do so until a) the queue is empty; and b) no more tasks are to be added to the queue. Commented Jan 22, 2013 at 1:09
  • @millimoose: If i understand correctly, thats exactly what benchmark marking tool does. Commented Jan 22, 2013 at 1:11

1 Answer 1

1

I am trying run a total of 8 threads on 4 cores.*

You're never going to run on more than 1 core with Python unless you (a) spawn multiple processes (not threads) or (b) use an alternate interpreter that doesn't have a Global Interpreter Lock.

The standard Python will not run python code in multiple threads at the same time.

Sign up to request clarification or add additional context in comments.

2 Comments

I am sorry, the comment got deleted by mistake.
Since I am using SPEC CPU BENCHMARK threads - I am able to bind them(2) to one core. I am not hyperthreading.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.