have been thinking about whether the program deliberately let the thread run on the specified CPU, which can improve operational efficiency, so specifically to write a code for CPU usage to draw a sine curve experiment, I use the AMD X4 641 CPU, four core four threads of the film.
The code is as follows
#include"stdafx.h"#include<iostream>#include<cmath>#include<ctime>#include<windows.h>using namespacestd;//get the number of seconds to loop 0xFFFFFFFF timesUnsignedintTest () {unsignedintc =0xFFFFFFFF; time_t T1, T2; Time (&t1); for(unsignedinti =0; I < C; i++) ; Time (&T2); return(unsignedint) (T2-t1);}#defineT 20000//Cycle Time 20 sec#defineC 100//sampling point time interval#definePI 3.1415//PIConstUnsignedintCount =0xFFFFFFFF/(Test () * +);//number of loops that can be executed at the sampling intervalConstUnsignedintN = T/C;//number of sample points during the cycleUnsignedintV[n] = {0};//continuous loop count for all sample pointsUnsignedintMt[n] = {0};//number of sleep milliseconds for all sample pointsintMain () {//Specify running CPUSetthreadaffinitymask (GetCurrentThread (),3);
for(inti =0; i < N; i++) { Doublex =2* PI * I/N; Doubler = (sin (x) +1) /2; Mt[i]= C-r *C; V[i]= R * C *count; } for(;;) { for(inti =0; i < N; i++) { for(intj =0; J < V[i]; J + +) ; Sleep (Mt[i]); } }}
No CPU is specified, and it looks like the system will split up to the first and second CPU usage
Specify to run on the first CPU, the effect is as follows:
Specify to run on the second CPU with the following effect:
Specify to run on the third CPU with the following effect:
Specify to run on the fourth CPU, the effect is as follows:
If specified, then will be fixed use that specified CPU, but a little more puzzled, the specified run on the first and second on the no problem, the specified run on the third, do not know which run on the top, and the specified run on the 4th, but run the 3rd CPU, is my CPU is a problem, Clearly is the Quad core four thread CPU, why the designation on the 3rd, no effect, and the designation on the fourth is running on the 3rd of it.
This is the result of AMD's CPU test, not knowing that Intel's CPU is not the same effect.
I'd like to switch to Intel's eight-core 16-thread CPU and feel that the quad-core four threads are now coping with the usual work.
After changing the eight-core 16-thread film, do the next test.
Multi-core CPU utilization test