使用两个线程时,性能提高了近66%。当我使用4个线程时,所需的时间与2个线程版本无异。我的系统是Linux 2.6.40.6-0.fc15.i686.PAE,处理器是Intel Core i5。
使用unix time命令(数组分配均匀的随机整数)对时间进行基准测试。在排序结束时,我会检查数组是否正确排序(非并行)。
使用4个线程时,CPU使用率约为80%至90%;使用2个线程时,CPU使用率约为50%;使用单个线程时,CPU使用率约为25%。
我本来期望在使用4个线程时有所加速。请问我有哪里出错了?
附:UPDATE 1这是代码:http://pastebin.com/9hQPhCa8。UPDATE 2我使用的处理器是Intel Core i5第二代。
cat /proc/cpuinfo | less
命令的输出结果(只显示核心0)。
处理器编号 :0 供应商ID :GenuineIntel CPU系列 :6 型号 :42 型号名称 :Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz 步进 :7 CPU主频 :800.000 MHz 缓存大小 :3072 KB 物理ID :0 同级处理器个数:4 核心编号 :0 CPU核心数量 :2 APIC ID :0 初始APIC ID :0 fdiv_bug :不受影响 hlt_bug :不受影响 f00f_bug :不受影响 coma_bug :不受影响 FPU支持 :是 FPU异常支持 :是 cpuid level :13 wp :启用了写保护 flags :fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 x2apic popcnt xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid BogoMIPS :4589.60 clflush大小 :64 缓存对齐方式 :64 地址位数 :物理36位,虚拟48位 电源管理 :