Skip to content

Commit

Permalink
Clean up script and add accumulate, reduce, file_write functions
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Tronge <[email protected]>
  • Loading branch information
jtronge committed Aug 6, 2024
1 parent e48c4a8 commit a41680e
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 153 deletions.
79 changes: 29 additions & 50 deletions ompi/mpi/bindings/ompi_bindings/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@
from ompi_bindings.parser import SourceTemplate


FortranParameter = namedtuple('FortranParameter', ['type_name', 'name', 'dep_params'])
FortranPrototype = namedtuple('FortranPrototype', ['fn_name', 'parameters'])


def load_prototypes(fname):
"""Load the prototypes from a JSON file."""
return []


class FortranBinding:
"""Class for generating the binding for a single function."""

Expand Down Expand Up @@ -197,21 +188,20 @@ def print_f_source_header(out):
"""Print the fortran f08 file header."""
out.dump(f'! {consts.GENERATED_MESSAGE}')
out.dump('#include "ompi/mpi/fortran/configure-fortran-output.h"')
out.dump('#include "mpi-f08-rename.h"')


def print_profiling_rename_macros(prototypes, out):
def print_profiling_rename_macros(templates, out):
"""Print macros for renaming functions for the profiling interface.
Previously hardcoded in mpi-f08-rename.h.
"""
out.dump('#if OMPI_BUILD_MPI_PROFILING')
for prototype in prototypes:
name = util.fortran_f08_name(prototype.fn_name)
for template in templates:
name = util.fortran_f08_name(template.prototype.name)
out.dump(f'#define {name} P{name}')
# Check for bigcount version
if util.fortran_prototype_has_bigcount(prototype):
bigcount_name = util.fortran_f08_name(prototype.fn_name, bigcount=True)
if util.fortran_prototype_has_bigcount(template.prototype):
bigcount_name = util.fortran_f08_name(template.prototype.name, bigcount=True)
out.dump(f'#define {bigcount_name} P{bigcount_name}')
out.dump('#endif /* OMPI_BUILD_MPI_PROFILING */')

Expand All @@ -230,6 +220,9 @@ def print_c_source_header(out, ts=False):
out.dump('#include "ompi/mpi/fortran/base/fint_2_int.h"')
out.dump('#include "ompi/request/request.h"')
out.dump('#include "ompi/communicator/communicator.h"')
out.dump('#include "ompi/win/win.h"')
out.dump('#include "ompi/file/file.h"')
out.dump('#include "ompi/errhandler/errhandler.h"')


def print_binding(prototype, lang, out, bigcount=False, template=None, ts=False):
Expand All @@ -241,65 +234,51 @@ def print_binding(prototype, lang, out, bigcount=False, template=None, ts=False)
binding.print_c_source()


def load_function_templates(prototype_files):
"""Load the templates from a file list."""
return [
SourceTemplate.load(fname, type_constructor=FortranType.construct)
for fname in prototype_files
]


def generate_code(args, out):
"""Generate binding code based on arguments."""
prototypes = load_prototypes(args.prototypes)
templates = load_function_templates(args.prototype_files)

if args.lang == 'fortran':
print_f_source_header(out)
out.dump()
print_profiling_rename_macros(prototypes, out)
print_profiling_rename_macros(templates, out)
out.dump()
else:
print_c_source_header(out, ts=True)
for prototype in prototypes:
out.dump()
print_binding(prototype, args.lang, out, ts=True)
if util.fortran_prototype_has_bigcount(prototype):
out.dump()
out.dump('#if OMPI_BIGCOUNT')
print_binding(prototype, args.lang, bigcount=True, out=out, ts=True)
out.dump('#endif /* OMPI_BIGCOUNT */')

for prototype_file in args.prototype_files:
tmpl = SourceTemplate.load(prototype_file, type_constructor=FortranType.construct)
for template in templates:
out.dump()
print_binding(tmpl.prototype, args.lang, out, template=tmpl, ts=True)
if util.fortran_prototype_has_bigcount(tmpl.prototype):
print_binding(template.prototype, args.lang, out, template=template, ts=True)
if util.fortran_prototype_has_bigcount(template.prototype):
out.dump()
out.dump('#if OMPI_BIGCOUNT')
print_binding(tmpl.prototype, args.lang, bigcount=True, out=out, template=tmpl, ts=True)
print_binding(template.prototype, args.lang, bigcount=True, out=out, template=template, ts=True)
out.dump('#endif /* OMPI_BIGCOUNT */')


def generate_interface(args, out):
"""Generate the Fortran interface files."""
prototypes = load_prototypes(args.prototypes)
out.dump(f'! {consts.GENERATED_MESSAGE}')
for prototype in prototypes:
ext_name = util.ext_api_func_name(prototype.fn_name)
out.dump(f'interface {ext_name}')
binding = FortranBinding(prototype, out=out, ts=True)
binding.print_interface()
if util.fortran_prototype_has_bigcount(prototype):
out.dump()
binding_c = FortranBinding(prototype, out=out, bigcount=True, ts=True)
out.dump('#if OMPI_BIGCOUNT')
binding_c.print_interface()
out.dump('#endif /* OMPI_BIGCOUNT */')
out.dump(f'end interface {ext_name}')

for prototype_file in args.prototype_files:
tmpl = SourceTemplate.load(prototype_file, type_constructor=FortranType.construct)
ext_name = util.ext_api_func_name(tmpl.prototype.name)
templates = load_function_templates(args.prototype_files)
for template in templates:
ext_name = util.ext_api_func_name(template.prototype.name)
out.dump(f'interface {ext_name}')
binding = FortranBinding(tmpl.prototype, template=tmpl, out=out, ts=True)
binding = FortranBinding(template.prototype, template=template, out=out, ts=True)
binding.print_interface()
if util.fortran_prototype_has_bigcount(tmpl.prototype):
if util.fortran_prototype_has_bigcount(template.prototype):
out.dump()
binding_c = FortranBinding(tmpl.prototype, out=out, template=tmpl,
binding_c = FortranBinding(template.prototype, out=out, template=template,
bigcount=True, ts=True)
out.dump('#if OMPI_BIGCOUNT')
binding_c.print_interface()
out.dump('#endif /* OMPI_BIGCOUNT */')
out.dump(f'end interface {ext_name}')
out.dump(f'! {prototype_file}')
40 changes: 36 additions & 4 deletions ompi/mpi/bindings/ompi_bindings/fortran_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ def c_parameter(self):
return f'{count_type} *{self.name}'


@FortranType.add('DISP')
@FortranType.add('AINT')
class Disp(FortranType):
"""Displacement type."""
"""MPI_Aint type."""

def declare(self):
return f'INTEGER(MPI_ADDRESS_KIND), INTENT(IN) :: {self.name}'
Expand All @@ -408,6 +408,24 @@ def c_parameter(self):
return f'MPI_Aint *{self.name}'


@FortranType.add('DISP')
class Disp(FortranType):
"""Displacecment type."""

def declare(self):
kind = '(KIND=MPI_ADDRESS_KIND)' if self.bigcount else ''
return f'INTEGER{kind}, INTENT(IN) :: {self.name}'

def use(self):
if self.bigcount:
return [('mpi_f08_types', 'MPI_ADDRESS_KIND')]
return []

def c_parameter(self):
count_type = 'MPI_Aint' if self.bigcount else 'MPI_Fint'
return f'{count_type} *{self.name}'


@FortranType.add('DISP_ARRAY')
class DispArray(IntArray):
"""Array of MPI_Aint or int."""
Expand Down Expand Up @@ -437,7 +455,7 @@ def use(self):
return [('mpi_f08_types', 'MPI_Op')]

def c_parameter(self):
return f'MPI_Op *{self.name}'
return f'MPI_Fint *{self.name}'


@FortranType.add('WIN')
Expand All @@ -451,4 +469,18 @@ def use(self):
return [('mpi_f08_types', 'MPI_Win')]

def c_parameter(self):
return f'MPI_Win *{self.name}'
return f'MPI_Fint *{self.name}'


@FortranType.add('FILE')
class File(FortranType):
"""MPI_File type."""

def declare(self):
return f'TYPE(MPI_File), INTENT(IN) :: {self.name}'

def use(self):
return [('mpi_f08_types', 'MPI_File')]

def c_parameter(self):
return f'MPI_Fint *{self.name}'
2 changes: 0 additions & 2 deletions ompi/mpi/fortran/use-mpi-f08/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ mpi_api_files = \
file_write_at_all_end_f08.F90 \
file_write_at_all_f08.F90 \
file_write_at_f08.F90 \
file_write_f08.F90 \
file_write_ordered_begin_f08.F90 \
file_write_ordered_end_f08.F90 \
file_write_ordered_f08.F90 \
Expand Down Expand Up @@ -373,7 +372,6 @@ mpi_api_files = \
query_thread_f08.F90 \
raccumulate_f08.F90 \
recv_init_f08.F90 \
reduce_f08.F90 \
reduce_init_f08.F90 \
reduce_local_f08.F90 \
reduce_scatter_f08.F90 \
Expand Down
2 changes: 2 additions & 0 deletions ompi/mpi/fortran/use-mpi-f08/Makefile.prototype_files
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,7 @@ ready_prototype_files = \
$(abs_top_srcdir)/ompi/mpi/fortran/use-mpi-f08/recv_ts.c.in \
$(abs_top_srcdir)/ompi/mpi/fortran/use-mpi-f08/isend_ts.c.in \
$(abs_top_srcdir)/ompi/mpi/fortran/use-mpi-f08/irecv_ts.c.in \
$(abs_top_srcdir)/ompi/mpi/fortran/use-mpi-f08/file_write_ts.c.in \
$(abs_top_srcdir)/ompi/mpi/fortran/use-mpi-f08/reduce_ts.c.in \
$(abs_top_srcdir)/ompi/mpi/fortran/use-mpi-f08/waitall.c.in \
$(abs_top_srcdir)/ompi/mpi/fortran/use-mpi-f08/testany.c.in
2 changes: 1 addition & 1 deletion ompi/mpi/fortran/use-mpi-f08/accumulate_ts.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

PROTOTYPE VOID accumulate(BUFFER x, COUNT origin_count,
DATATYPE origin_datatype, RANK target_rank,
DISP target_disp, COUNT target_count,
AINT target_disp, COUNT target_count,
DATATYPE target_datatype, OP op, WIN win)
{
int c_ierr;
Expand Down
30 changes: 0 additions & 30 deletions ompi/mpi/fortran/use-mpi-f08/file_write_f08.F90

This file was deleted.

14 changes: 2 additions & 12 deletions ompi/mpi/fortran/use-mpi-f08/file_write_ts.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,8 @@
* $HEADER$
*/

#include "ompi_config.h"

#include "ompi/file/file.h"
#include "ompi/errhandler/errhandler.h"
#include "ompi/mpi/fortran/use-mpi-f08/ts/bindings.h"
#include "ompi/mpi/fortran/mpif-h/status-conversion.h"
#include "ompi/mpi/fortran/base/constants.h"

static const char FUNC_NAME[] = "MPI_File_write";

void ompi_file_write_ts(MPI_Fint *fh, CFI_cdesc_t *x, MPI_Fint *count,
MPI_Fint *datatype, MPI_Fint *status, MPI_Fint *ierr)
PROTOTYPE VOID file_write(FILE fh, BUFFER x, COUNT count,
DATATYPE datatype, STATUS_OUT status)
{
int c_ierr;
MPI_File c_fh = PMPI_File_f2c(*fh);
Expand Down
31 changes: 0 additions & 31 deletions ompi/mpi/fortran/use-mpi-f08/reduce_f08.F90

This file was deleted.

15 changes: 3 additions & 12 deletions ompi/mpi/fortran/use-mpi-f08/reduce_ts.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,9 @@
* $HEADER$
*/

#include "ompi_config.h"

#include "ompi/communicator/communicator.h"
#include "ompi/errhandler/errhandler.h"
#include "ompi/mpi/fortran/use-mpi-f08/ts/bindings.h"
#include "ompi/mpi/fortran/base/constants.h"

static const char FUNC_NAME[] = "MPI_Reduce";

void ompi_reduce_ts(CFI_cdesc_t *x1, CFI_cdesc_t *x2, MPI_Fint *count,
MPI_Fint *datatype, MPI_Fint *op,
MPI_Fint *root, MPI_Fint *comm, MPI_Fint *ierr)
PROTOTYPE VOID reduce(BUFFER x1, BUFFER_OUT x2, COUNT count,
DATATYPE datatype, OP op,
RANK root, COMM comm)
{
int c_ierr;
MPI_Datatype c_type;
Expand Down
13 changes: 2 additions & 11 deletions ompi/mpi/fortran/use-mpi-f08/win_create_ts.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,8 @@
* $HEADER$
*/

#include "ompi_config.h"

#include "ompi/communicator/communicator.h"
#include "ompi/errhandler/errhandler.h"
#include "ompi/mpi/fortran/use-mpi-f08/ts/bindings.h"

static const char FUNC_NAME[] = "MPI_Win_create";

void ompi_win_create_ts(CFI_cdesc_t *x, MPI_Aint *size, MPI_Fint *disp_unit,
MPI_Fint *info, MPI_Fint *comm, MPI_Fint *win,
MPI_Fint *ierr)
PROTOTYPE VOID win_create(BUFFER x, AINT size, DISP disp_unit,
INFO info, COMM comm, WIN_OUT win)
{
int c_ierr;
MPI_Win c_win;
Expand Down

0 comments on commit a41680e

Please sign in to comment.