本部分说明如何使用 er_print 命令行和线程分析器 GUI 显示有关检测到的每个数据争用的以下信息:
数据争用的唯一 ID。
与数据争用关联的虚拟地址 Vaddr。如果存在多个虚拟地址,则在圆括号中显示标签“多个地址”。
两个不同线程对虚拟地址 Vaddr 的内存访问。显示访问类型(读取或写入),以及源代码中发生访问处的函数、偏移量和行号。
与数据争用关联的跟踪总数。每个跟踪都引用发生两个数据争用访问时的线程调用栈对。如果使用 GUI,则选择单个跟踪时 Race Details(争用详细信息)选项卡中将显示这两个调用栈。如果使用 er_print 实用程序,则 rdetail 命令将显示这两个调用栈。
% cc -xopenmp=noopt omp_prime.c -lm -xinstrument=datarace
% collect -r race a.out | sort -n
0
0
0
0
0
0
0
0
0
0
...
0
0
Creating experiment database test.1.er ...
Number of prime numbers between 2 and 3000: 429
2
3
5
7
11
13
17
19
23
29
31
37
41
47
53
59
61
67
71
73
...
2971
2999
% er_print test.1.er
(er_print) races
Total Races: 4 Experiment: test.1.er
Race #1, Vaddr: 0xffbfeec4
Access 1: Read, main -- MP doall from line 42 [_$d1A42.main] + 0x00000060,
line 45 in "omp_prime.c"
Access 2: Write, main -- MP doall from line 42 [_$d1A42.main] + 0x0000008C,
line 46 in "omp_prime.c"
Total Traces: 2
Race #2, Vaddr: 0xffbfeec4
Access 1: Write, main -- MP doall from line 42 [_$d1A42.main] + 0x0000008C,
line 46 in "omp_prime.c"
Access 2: Write, main -- MP doall from line 42 [_$d1A42.main] + 0x0000008C,
line 46 in "omp_prime.c"
Total Traces: 1
Race #3, Vaddr: (Multiple Addresses)
Access 1: Write, main -- MP doall from line 42 [_$d1A42.main] + 0x0000007C,
line 45 in "omp_prime.c"
Access 2: Write, main -- MP doall from line 42 [_$d1A42.main] + 0x0000007C,
line 45 in "omp_prime.c"
Total Traces: 1
Race #4, Vaddr: 0x21418
Access 1: Read, is_prime + 0x00000074,
line 18 in "omp_prime.c"
Access 2: Write, is_prime + 0x00000114,
line 21 in "omp_prime.c"
Total Traces: 1
(er_print)
以下屏幕快照显示在 omp_primes.c 中检测到的争用,与线程分析器 GUI 显示的相同。调用 GUI 并装入实验数据的命令是 tha test.1.er。

在 omp_primes.c 中有以下四个数据争用:
一号争用:第 45 行上 total 的读取和第 46 行上 total 的写入之间的数据争用。
二号争用:第 46 行上 total 的写入和同一行上 total 的另一写入之间的数据争用。
三号争用:第 45 行上 primes[] 的写入和同一行上 primes[] 的另一写入之间的数据争用。
四号争用:第 18 行上 pflag[] 的读取和第 21 行上 pflag[] 的写入之间的数据争用。
% cc pthr_prime.c -lm -mt -xinstrument=datarace .
% collect -r on a.out | sort -n
Creating experiment database test.2.er ...
of type "nfs", which may distort the measured performance.
0
0
0
0
0
0
0
0
0
0
...
0
0
Creating experiment database test.2.er ...
Number of prime numbers between 2 and 3000: 328
751
757
761
773
797
809
811
821
823
827
829
839
853
857
859
877
881
883
887
907
...
2999
2999
% er_print test.2.er
(er_print) races
Total Races: 6 Experiment: test.2.er
Race #1, Vaddr: 0x218d0
Access 1: Write, work + 0x00000154,
line 40 in "pthr_prime.c"
Access 2: Write, work + 0x00000154,
line 40 in "pthr_prime.c"
Total Traces: 3
Race #2, Vaddr: 0x218d0
Access 1: Read, work + 0x000000CC,
line 39 in "pthr_prime.c"
Access 2: Write, work + 0x00000154,
line 40 in "pthr_prime.c"
Total Traces: 3
Race #3, Vaddr: 0xffbfeec4
Access 1: Write, main + 0x00000204,
line 55 in "pthr_prime.c"
Access 2: Read, work + 0x00000024,
line 35 in "pthr_prime.c"
Total Traces: 2
Race #4, Vaddr: (Multiple Addresses)
Access 1: Write, work + 0x00000108,
line 39 in "pthr_prime.c"
Access 2: Write, work + 0x00000108,
line 39 in "pthr_prime.c"
Total Traces: 1
Race #5, Vaddr: 0x23bfc
Access 1: Write, is_prime + 0x00000210,
line 22 in "pthr_prime.c"
Access 2: Write, is_prime + 0x00000210,
line 22 in "pthr_prime.c"
Total Traces: 1
Race #6, Vaddr: 0x247bc
Access 1: Write, work + 0x00000108,
line 39 in "pthr_prime.c"
Access 2: Read, main + 0x00000394,
line 65 in "pthr_prime.c"
Total Traces: 1
(er_print)
以下屏幕快照显示在 pthr_primes.c 中检测到的争用,与线程分析器 GUI 显示的相同。调用 GUI 和装入实验数据的命令是 tha test.2.er。

在 pthr_prime.c 中有以下六个数据争用:
一号争用:第 40 行上 total 的写入和同一行上 total 的另一写入之间的数据争用。
二号争用:第 39 行上 total 的读取和第 40 行上 total 的写入之间的数据争用。
三号争用:第 55 行上 i 的写入和第 35 行上 i 的读取之间的数据争用。
四号争用:第 39 行上primes[] 的写入和同一行上primes[] 的另一写入之间的数据争用。
五号争用:第 22 行上 pflag[] 的写入和同一行上 pflag[] 的另一写入之间的数据争用
六号争用:第 39 行上 primes[] 的写入和第 65 行上 primes[] 的读取之间的数据争用。
GUI 的一个优势在于,它允许您并排查看与数据争用关联的两个源位置。例如,在 Races(争用)选项卡中选择 pthr_prime.c 的六号争用,然后单击“双重数据源”选项卡。您将看到以下内容:

在顶部 "Race Source" 窗格中显示六号争用(第 39 行)的第一次访问,在底部窗格中则显示该数据争用的第二次访问。突出显示其中发生数据争用访问的源代码(第 39 行和第 65 行)。在每个源代码行的左侧显示缺省度量(互斥争用访问度量)。该度量显示在该行上报告的数据争用访问次数。