1+ #!/usr/bin/env python3
2+ """
3+ Demonstration of the OpenMP linear clause fix for issue #320.
4+
5+ This script shows how the fix addresses the GCC compilation issue
6+ with OpenMP SIMD pragmas in non-canonical loop forms.
7+ """
8+
9+ def demonstrate_fix ():
10+ """
11+ Show the key components of the fix and what it accomplishes.
12+ """
13+ print ("OpenMP Linear Clause Fix for GCC Compatibility (Issue #320)" )
14+ print ("=" * 60 )
15+
16+ print ("\n 1. PROBLEM DESCRIPTION:" )
17+ print (" - GCC doesn't accept 'pragma omp simd' with non-canonical loop forms" )
18+ print (" - This occurs when blockinner=True creates complex nested loops" )
19+ print (" - ICC is more permissive and doesn't have this issue" )
20+ print (" - Needed for GCC >= 4.9 (which supports OpenMP 4.0)" )
21+
22+ print ("\n 2. SOLUTION IMPLEMENTED:" )
23+ print (" - Added OpenMP 'linear' clause to SIMD pragmas when needed" )
24+ print (" - Linear clause tells OpenMP that variables change linearly with iteration" )
25+ print (" - Only applied for GCC compiler, not ICC" )
26+ print (" - Automatically detects when linear clauses are needed" )
27+
28+ print ("\n 3. PRAGMA TRANSFORMATIONS:" )
29+ print (" Before (problematic for GCC):" )
30+ print (" #pragma omp simd" )
31+ print (" for (int i = ...)" )
32+ print (" for (int j = ...)" )
33+ print ()
34+ print (" After (GCC compatible):" )
35+ print (" #pragma omp simd linear(i,j)" )
36+ print (" for (int i = ...)" )
37+ print (" for (int j = ...)" )
38+
39+ print ("\n 4. NEW PRAGMA VARIANTS ADDED:" )
40+ variants = [
41+ ("simd-for" , "Basic SIMD pragma" ),
42+ ("simd-for-linear" , "SIMD with linear clause" ),
43+ ("simd-for-aligned-linear" , "SIMD with both aligned and linear clauses" )
44+ ]
45+
46+ for variant , description in variants :
47+ print (f" - { variant } : { description } " )
48+
49+ print ("\n 5. DETECTION LOGIC:" )
50+ conditions = [
51+ "Using GCC compiler (not ICC)" ,
52+ "GCC version >= 4.9 (OpenMP 4.0 support)" ,
53+ "Complex nested loop structure detected (3+ levels)" ,
54+ "Block dimensions or common loop indices present"
55+ ]
56+
57+ for i , condition in enumerate (conditions , 1 ):
58+ print (f" { i } . { condition } " )
59+
60+ print ("\n 6. CODE LOCATIONS MODIFIED:" )
61+ files = [
62+ "devito/passes/iet/languages/openmp.py - Added new pragma variants" ,
63+ "devito/passes/iet/parpragma.py - Enhanced SIMD pragma generation logic"
64+ ]
65+
66+ for file_info in files :
67+ print (f" - { file_info } " )
68+
69+ print ("\n 7. BENEFITS:" )
70+ benefits = [
71+ "GCC compilation works with blockinner=True and aggressive DSE" ,
72+ "ICC compatibility maintained (no linear clauses added unnecessarily)" ,
73+ "Automatic detection - no user configuration required" ,
74+ "Backward compatible with existing code"
75+ ]
76+
77+ for benefit in benefits :
78+ print (f" ✓ { benefit } " )
79+
80+
81+ def show_example_scenarios ():
82+ """
83+ Show example scenarios where the fix would be applied.
84+ """
85+ print ("\n " + "=" * 60 )
86+ print ("EXAMPLE SCENARIOS" )
87+ print ("=" * 60 )
88+
89+ scenarios = [
90+ {
91+ "name" : "TTI (Tilted Transverse Isotropy) with 3D blocking" ,
92+ "description" : "Complex seismic stencil with blockinner=True" ,
93+ "triggers_fix" : True ,
94+ "reason" : "Multiple nested loops with block dimensions"
95+ },
96+ {
97+ "name" : "Simple 2D heat equation without blocking" ,
98+ "description" : "Basic stencil with no blocking transformations" ,
99+ "triggers_fix" : False ,
100+ "reason" : "No complex loop nesting"
101+ },
102+ {
103+ "name" : "3D acoustic stencil with blockinner=True" ,
104+ "description" : "3D space-order stencil with aggressive blocking" ,
105+ "triggers_fix" : True ,
106+ "reason" : "Deep loop nesting from blocking"
107+ },
108+ {
109+ "name" : "Same code compiled with ICC" ,
110+ "description" : "Any stencil using Intel compiler" ,
111+ "triggers_fix" : False ,
112+ "reason" : "ICC doesn't need linear clauses"
113+ }
114+ ]
115+
116+ for i , scenario in enumerate (scenarios , 1 ):
117+ print (f"\n { i } . { scenario ['name' ]} " )
118+ print (f" Description: { scenario ['description' ]} " )
119+ print (f" Triggers fix: { 'Yes' if scenario ['triggers_fix' ] else 'No' } " )
120+ print (f" Reason: { scenario ['reason' ]} " )
121+
122+
123+ def show_testing_approach ():
124+ """
125+ Explain how the fix can be tested.
126+ """
127+ print ("\n " + "=" * 60 )
128+ print ("TESTING APPROACH" )
129+ print ("=" * 60 )
130+
131+ tests = [
132+ {
133+ "type" : "Unit Tests" ,
134+ "description" : "Test pragma generation logic in isolation" ,
135+ "file" : "test_linear_clause_unit.py"
136+ },
137+ {
138+ "type" : "Integration Tests" ,
139+ "description" : "Test with actual Devito operators and blocking" ,
140+ "file" : "test_linear_pragma_fix.py"
141+ },
142+ {
143+ "type" : "Regression Tests" ,
144+ "description" : "Ensure existing functionality still works" ,
145+ "file" : "Existing test suite (test_dle.py, etc.)"
146+ },
147+ {
148+ "type" : "Compiler Tests" ,
149+ "description" : "Test with both GCC and ICC to ensure compatibility" ,
150+ "file" : "Manual testing with different compilers"
151+ }
152+ ]
153+
154+ for test in tests :
155+ print (f"\n • { test ['type' ]} " )
156+ print (f" { test ['description' ]} " )
157+ print (f" Location: { test ['file' ]} " )
158+
159+
160+ if __name__ == "__main__" :
161+ demonstrate_fix ()
162+ show_example_scenarios ()
163+ show_testing_approach ()
164+
165+ print ("\n " + "=" * 60 )
166+ print ("SUMMARY" )
167+ print ("=" * 60 )
168+ print ("This fix resolves issue #320 by automatically adding OpenMP 'linear'" )
169+ print ("clauses to SIMD pragmas when using GCC with complex loop structures" )
170+ print ("from blocking transformations. The fix is conservative, automatic," )
171+ print ("and maintains compatibility with both GCC and ICC compilers." )
172+ print ()
173+ print ("The implementation is ready for testing with TTI examples and" )
174+ print ("other complex stencils that use blockinner=True with aggressive DSE." )
0 commit comments