Skip to content

Commit

Permalink
mpicc and mpic++ are default compilers and help updated
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarpomar committed Nov 7, 2023
1 parent a4a9148 commit d7b4747
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
39 changes: 18 additions & 21 deletions mpi4all/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,33 @@
def cli():
parser = argparse.ArgumentParser(prog='mpi4all', description='A script to generate mpi bindings')
parser.add_argument('--out', dest='out', action='store', metavar='path',
help='output folder, by default is working directory', default='./')
help='Output folder, by default is working directory', default='./')
parser.add_argument('--log', dest='log', action='store', metavar='lvl', choices=['info', 'warn', 'error'],
default='error', help='log level, default error')
default='error', help='Log level, default error')

p_parser = parser.add_argument_group('Mpi parser arguments')
p_parser.add_argument('--gcc', dest='gcc', action='store', metavar='path',
help='path of gcc binary, by default use the gcc in PATH', default="gcc")
p_parser.add_argument('--g++', dest='gpp', action='store', metavar='path',
help='path of g++ binary, by default use the g++ in PATH', default='g++')
p_parser.add_argument('--mpi', dest='mpi', action='store', metavar='path',
help='force a directory to search for mpi.h', default=None)
p_parser.add_argument('--cc', dest='cc', action='store', metavar='path',
help='MPI C compiler, by default uses the \'mpicc\' in PATH', default="mpicc")
p_parser.add_argument('--cxx', dest='cxx', action='store', metavar='path',
help='MPI C++ compiler, by default uses the \'mpic++\' in PATH', default='mpic++')
p_parser.add_argument('--exclude', dest='exclude', action='store', metavar='str', nargs='+', default=[],
help='exclude functions and macros that match with any pattern')
help='Exclude functions and macros that match with any pattern')
p_parser.add_argument('--enable-fortran', dest='fortran', action='store_true',
help='enable mpi fortran functions disabled by default to avoid linking errors, '
help='Parse MPI Fortran functions, which are disabled by default, to avoid linking errors '
'if they are not available', default=False)
p_parser.add_argument('--no-arg-names', dest='no_arg_names', action='store_true',
help='use xi as param name in mpi functions', default=False)
help='Use xi as the parameter name in MPI functions', default=False)
p_parser.add_argument('--dump', dest='dump', action='store', metavar='path', default=None,
help='dump parser output as specification file, - for stdout')
help='Dump parser output as json file, - for stdout')
p_parser.add_argument('--load', dest='load', action='store', metavar='path', default=None,
help='ignore parser and load info from a specification file, - for stdin')
help='Don\'t use a parser and load info from a JSON file, - for stdin')
p_parser.add_argument('--cache', dest='cache', action='store', metavar='path', default=None,
help='make --dump if the file does not exist and --load otherwise')
help='Make --dump if the file does not exist and --load otherwise')

go_parser = parser.add_argument_group('Go builder arguments')
go_parser.add_argument('--go', dest='go', action='store_true',
help='enable Go generator')
go_parser.add_argument('--no-generic', dest='gogeneric', action='store_false',
help='Enable Go generator')
go_parser.add_argument('--no-generic', dest='go_generic', action='store_false',
help='Disable utility functions that require go 1.18+', default=True)

go_parser.add_argument('--go-package', dest='go_package', action='store', metavar='name',
Expand All @@ -51,7 +49,7 @@ def cli():

java_parser = parser.add_argument_group('Java builder arguments')
java_parser.add_argument('--java', dest='java', action='store_true',
help='enable Java 21 generator')
help='Enable Java 21 generator')
java_parser.add_argument('--java-package', dest='java_package', action='store', metavar='name',
help='Java package name, default org.mpi', default='org.mpi')
java_parser.add_argument('--java-class', dest='java_class', action='store', metavar='name',
Expand Down Expand Up @@ -96,9 +94,8 @@ def main():
mpi_info = json.load(file)
else:
mpi_info = MpiParser(
gcc=args.gcc,
gpp=args.gpp,
mpih=args.mpi,
cc=args.cc,
cxx=args.cxx,
exclude_list=args.exclude,
get_func_args=not args.no_arg_names
).parse()
Expand All @@ -114,7 +111,7 @@ def main():
logging.info("Generating Go source")
GoBuilder(
package=args.go_package,
generic=args.gogeneric,
generic=args.go_generic,
out=args.go_out if args.go_out else args.out,
).build(mpi_info)
logging.info("Go source Ready")
Expand Down
26 changes: 13 additions & 13 deletions mpi4all/mpiparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@
class MpiParser:
CAST_RE = re.compile(r'^\(?\((MPI_\w+[ *]*)\)|OMPI_PREDEFINED_GLOBAL\([ ]*(MPI_\w+[ *]*)')

def __init__(self, gcc, gpp, mpih, exclude_list, get_func_args):
self._gcc = [gcc, '-I' + mpih] if mpih else [gcc]
self._gpp = [gpp, '-I' + mpih] if mpih else [gpp]
def __init__(self, cc, cxx, exclude_list, get_func_args):
self._cc = cc.split()
self._cxx = cxx.split()
self._exclude_patterns = list(map(lambda e: re.compile(e), exclude_list))
self._get_func_args = get_func_args
self._types = dict()
self._info = dict()

try:
logging.info('Checking C compiler')
self._run(self._gcc + ['--version'])
self._run(self._cc + ['--version'])
logging.info('C compiler OK')
except subprocess.CalledProcessError as ex:
raise RuntimeError(self._gcc[0] + ' not found')
raise RuntimeError(self._cc[0] + ' not found')

try:
logging.info('Checking C++ compiler')
self._run(self._gpp + ['--version'])
self._run(self._cxx + ['--version'])
logging.info('C++ compiler OK')
except subprocess.CalledProcessError as ex:
raise RuntimeError(self._gpp[0] + ' not found')
raise RuntimeError(self._cxx[0] + ' not found')

try:
logging.info('Checking header mpi.h')
self._run(self._gcc + ['-dM', '-E', '-include', 'mpi.h', '-'])
self._run(self._cc + ['-dM', '-E', '-include', 'mpi.h', '-'])
logging.info('Header mpi.h OK')
except subprocess.CalledProcessError as ex:
raise RuntimeError('mpi.h not found')
Expand Down Expand Up @@ -74,11 +74,11 @@ def _c_info(self, name, wd):
file.flush()

try:
self._run(self._gpp + ['-fpermissive', cpp, '-o', bin])
self._run(self._cxx + ['-fpermissive', cpp, '-o', bin])
typename, bytes = self._run([bin]).stdout.split('\n')[:2]

i = 'auto x = ' + name + ';'
if self._run(self._gpp + ['--shared', '-include', 'mpi.h', '-o', '/dev/null', '-x', 'c++', '-'],
if self._run(self._cxx + ['--shared', '-include', 'mpi.h', '-o', '/dev/null', '-x', 'c++', '-'],
check=False, input=i).returncode == 0:
var = True
else:
Expand Down Expand Up @@ -140,7 +140,7 @@ def _parse_macro(self, macro, wd):

def _parse_macros(self, wd):
logging.info('getting macros')
macro_dump = self._run(self._gcc + ['-dM', '-E', '-include', 'mpi.h', '-']).stdout
macro_dump = self._run(self._cc + ['-dM', '-E', '-include', 'mpi.h', '-']).stdout
with ThreadPoolExecutor() as workers:
logging.info('parsing macros')
all_macros = workers.map(lambda m: self._parse_macro(m, wd), macro_dump.split('\n'))
Expand Down Expand Up @@ -175,7 +175,7 @@ def _parse_macros(self, wd):
def _parse_funcs(self, wd):
func_file = os.path.join(wd, 'func.X')
self._run(
self._gcc + ['-x', 'c', '-shared', '-o', '/dev/null', '-aux-info', func_file, '-include', 'mpi.h', '-'])
self._cc + ['-x', 'c', '-shared', '-o', '/dev/null', '-aux-info', func_file, '-include', 'mpi.h', '-'])

with open(func_file) as file:
func_dump = file.readlines()
Expand Down Expand Up @@ -239,7 +239,7 @@ def search(arg):
functions.append(f)

if self._get_func_args:
name_info = self._run(self._gcc + ['-E', '-include', 'mpi.h', '-']).stdout
name_info = self._run(self._cc + ['-E', '-include', 'mpi.h', '-']).stdout
for f in functions:
try:
start = name_info.index(f['name'] + '(')
Expand Down
4 changes: 3 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def build_ompi(name, v):


def parser(path):
cmd(['docker', 'run', '--rm', '-v', path + ':/mpi', 'mpi4all', '--mpi', '/mpi/include', '--dump', '/mpi/f.json'])
cmd(['docker', 'run', '--rm', '-v', path + ':/mpi', 'mpi4all',
'--cc', 'gcc -I /mpi/include',
'--cxx', 'g++ -I /mpi/include', '--dump', '/mpi/f.json'])


def go_builder(path):
Expand Down

0 comments on commit d7b4747

Please sign in to comment.