1#!/usr/bin/python 2# -*- coding: utf-8 -*- 3 4import sys 5import re 6from os.path import basename 7 8total_matches = 0 9 10#=============================================================================== 11def main(): 12 if(len(sys.argv) < 2): 13 print("Tool for finding common mistakes with OMP pragmas.") 14 print("Hint: It expects DEFAULT(NONE) in the first line of a PARALLEL pragma.") 15 print("Usage: find_openmp_mistakes.py <file1.F> ... <fileN.F>") 16 sys.exit(1) 17 18 files = sys.argv[1:] 19 for fn in files: 20 check(fn) 21 22 print("Found %d spots in %d files."%(total_matches, len(files))) 23 24#=============================================================================== 25def check(fn): 26 global total_matches 27 28 f = open(fn) 29 all_lines = f.read().split("\n") 30 31 for lineno, line in enumerate(all_lines): 32 m = re.search("^\s*!(.*)OMP\s", line, re.IGNORECASE) 33 if(m and m.group(1)!="$"): 34 total_matches += 1 35 print('Found strange OMP stuff "%s" in %s:%d'%(m.group(0), basename(fn), lineno+1)) 36 37 m = re.search("!\$OMP\s+CRITICAL\s*$", line, re.IGNORECASE) 38 if(m): 39 total_matches += 1 40 print('Found unnamed OMP CRITICAL in %s:%d'%(basename(fn), lineno+1)) 41 42 43 m = re.search("!\$OMP\s+PARALLEL\s+(.*)$", line, re.IGNORECASE) 44 if(m): 45 m2 = re.search("default\s*\(none\)", m.group(1), re.IGNORECASE) 46 if(not m2): 47 total_matches += 1 48 print('Found OMP PARALLEL without DEFAULT(NONE) %s:%d'%(basename(fn), lineno+1)) 49 #print line 50 51 52 53#=============================================================================== 54main() 55