News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Threading

Started by Astro, July 14, 2009, 08:36:46 PM

Previous topic - Next topic

Tedd

There's no contradiction.

Quote from: Tedd on July 15, 2009, 11:48:25 AM
Unless you create extra threads, your program is singe-threaded.
That single thread will run on ONE single processor core at a time.
If the machine contains multiple cores/processors, your program will still only run on ONE at any instance in time.
It may migrate between cores during context switches, but this should be transparent to the running of your program, unless you specifically check which core you're running on.
You can fix your thread to run only on a specific core by setting its affinity to that core. However, this may limit the running of your thread since that core will also be used by other threads, even while the other cores are free and ready to run.


A single-threaded process will only use one core at a time, not many at once. However, through the lifetime of execution, it may execute time slices on different cores (which is what you can measure.)
No snowflake in an avalanche feels responsible.

dedndave

ApicID (core ID) = CPUID (function eax=1) ebx register, bits 24-31

source and program attached
Code:

;--------------------------------------------

        include        c:\masm32\include\masm32rt.inc
        .586

;--------------------------------------------

        .code

;--------------------------------------------

_main   PROC

        mov     ecx,10000

test00: push    ecx
        mov     eax,1
        cpuid
        rol     ebx,8
        and     ebx,0FFh
        print   str$(ebx)
        pop     ecx
        loop    test00

        inkey
        exit

_main   ENDP

;--------------------------------------------

        END     _main

Result (P4 Prescott):

00000000000000000000000000000000000011111111111111111111111111111111111111111000
00000000000000000000000000000000000000111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111100000000000000000000000000000
00000000000000000000000000000000000000000000000000000001111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111000000000000000000
00000000000000000000000000000000000000000000000000000000000000000111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111100000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000111111111111111111111111111111111111111
11111111111111111111111111111111111011111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111000000000011111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111110000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000111111
01111111111111111111111111111111111111111111111111111111111111111111111111111100
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000011111111111111111111111111111111111111111111111111
01111111111110000000011111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111110000000000
10000000000000000000000000000000000000000000000000000111111111111111111111111111
01111111111111111111111111111111111101111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01110000000000000000000000000000000000000000000000000000000000000000000000000000
01111111111111111111111111111111111111111111111111111111111111111111111100000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000001111111111111111111111111111111111111111
01111111111111111111111000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000011111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111000000000000000000000000000000000000000
10000000000000000000000010111000011110111011101110111011101111111011100111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
00000000000000000000000000000000000000000000000000000000000000000000000000000000
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111100000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
01111111111111111111111111111110000000000111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111000000001111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111100000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000111
01111111111111111110000000000000000000000000000000000000000000000000000000000000
10011111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111100000000000000000000000000
10000000000000000000000000000000000001000000000000000000000000000000000000000000
10000000000000000000111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000001111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111100000000000000000000000
10000000000000000000000000000000000000000011111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111110000000000000001111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
01111111111111111111111111111111111111111111111111111111111111111110000000000111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000001111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
00000000000000000000000000000000000000000000000000000000000000000111111111111111
01111111111111111111111111111111111111111111111100000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000011111111111111111111111111111111111111111111111111111111111111111111111
01111100000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000011111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111100000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10011111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000001111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111110000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000001
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111110000000000000000000000000000000000
00000000011111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111000000000000000000000000000
01111111111111111111111111111111111111111111111111111111111111111111111111111111


[attachment deleted by admin]

Astro

I thought a thread was the little bit of my program that was actually being executed at any moment?

dedndave

no - threads are essentially "mini-processes"
one process (i.e. program) may create several threads
the test above tests cores
unless your program specifically creates more than one thread, it is a single thread that may run on multiple cores

Astro

Out of interest...

Intel Core2 Duo E6700.

If I use the command line:

cpuid.exe > cpuid.txt

the core is consistently 0 or 1. No change.

00000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000110000111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111100010000001000000000000000011111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111110010010001111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000100100011111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111110000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000000000000110000000000000
00000000000000000000000000011111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111
01111111111111111111111111111111111111111111111111111111111111111111111111111111

Astro

Quote from: dedndave on July 15, 2009, 03:18:45 PM
no - threads are essentially "mini-processes"
one process (i.e. program) may create several threads
the test above tests cores
unless your program specifically creates more than one thread, it is a single thread that may run on multiple cores
OK - thanks.  :thumbu

Astro

Curious behavior... Each line has the general pattern:

100000........
100000........
011111........
011111........

dedndave

lol
that is curious
that would seem to indicate that each time the program scrolls, the core switches
probably waiting for the scroll to complete - so switches to the other core to process other instructions (guessing)
i am running XP MCE2005 (Pro) +SP2

dedndave

yours appears to stay with one core longer
that is a bit misleading, as we have no time-marker - only instruction cycles
i like yours better - it seems more "settled"
more than likely, yours is executing more instructions in a given time period than mine is
well - i know it is - core duo's are smokin cpu's in terms of clock cycles

Astro

I wondered the same.

If I output to a text file, it runs on one core the whole time (either 0 or 1).

dedndave

mine does that too

Astro

Forgot to add - Win XP Pro SP3. I'll try it on Vista 64-bit and see what it does.

Tedd

When you output text to the console, your thread is blocked until the console updates - so you waste half your slice doing nothing. When you output to a file, it's buffered, so the delay is minimal.
No snowflake in an avalanche feels responsible.

Astro

Yes - it's something I noticed with Windows apps too - if it has to update the display it is 1/10th the speed of when it doesn't...

Logman

I am new to this forum having just switched over from FASM/NASM. I switched back to MASM32 because I used to use MASM/TASM back in the CPM/DOS days and am more comfortable with it's structure and overall capabilities.

Anyway, speaking of multi-core processors, does anyone know where I can find code that would detect whether or not my program is running on a multi-core processor?

Logman
If you read the fine print, you'll get an education. If you don't, you'll get experience!