-
Notifications
You must be signed in to change notification settings - Fork 18
/
psydac_accelerate.py
58 lines (43 loc) · 2 KB
/
psydac_accelerate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import argparse
import os
from subprocess import run as sub_run
import shutil
#The purpose of this file is to be launched after an editable installation of Psydac, to pyccelise all the Psydac kernels.
#This file is useless during a classic installation because the kernels are already pyccelised in the construction folder.
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description="Accelerate all computational kernels in Psydac using Pyccel (editable install only)"
)
# Add Argument --language at the pyccel command
parser.add_argument('--language',
type=str,
default='fortran',
choices=['fortran', 'c'],
action='store',
dest='language',
help='Language used to pyccelize all the _kernels files'
)
# Add flag --openmp at the pyccel command
parser.add_argument('--openmp',
default=False,
action='store_true',
dest='openmp',
help="Use OpenMP multithreading in generated code."
)
# Read input arguments
args = parser.parse_args()
# get the absolute path to the psydac directory
psydac_path = os.path.dirname(os.path.abspath(__file__))+'/psydac'
print("\nNOTE: This script should only be used if Psydac was installed in editable mode.\n")
# Define all the parameters of the command in the parameters array
parameters = ['--language', args.language]
# check if the flag --openmp is passed and add it to the argument if it's the case
if args.openmp:
parameters.append('--openmp')
# search in psydac/psydac folder all the files ending with the tag _kernels.py
for path, subdirs, files in os.walk(psydac_path):
for name in files:
if name.endswith('_kernels.py'):
print(' Pyccelize file: ' + os.path.join(path, name))
sub_run([shutil.which('pyccel'), os.path.join(path, name), *parameters], shell=False)
print()