=head1 NAME

CFX5::Parallel::MPI - MPI utility routines

=head1 SYNOPSIS

This module contains utility routines for MPI

COPYRIGHT ANSYS, ALL RIGHTS RESERVED

=cut

package CFX5::Parallel::MPI;

use strict;

use CFX5::PathManip qw(join_file);
use CFX5::Config qw(%Config prepend_to_libpath);

=head2 export_conf

  CFX5::Parallel::MPI::export_conf();

  Set and export configuration variables required by MPI

=cut

# Maybe split into different MPI types

sub export_conf
{
  if ($Config{windows_nt})
  {
    prepend_to_libpath(join_file($Config{CFX5_IBMMPI_DIR}, 'bin'));
    prepend_to_libpath(join_file($Config{CFX5_IMPI_DIR}, 'bin'));
  }

  if ($Config{CFX_OS} eq 'Linux')
  {
    my %ibmmpi_arch = ('linux'       => 'linux_ia32',
                       'linux-amd64' => 'linux_amd64');

    my $cfxos = $Config{CFX5OS};

    prepend_to_libpath(join_file($Config{CFX5_IBMMPI_DIR}, 'lib', $ibmmpi_arch{$cfxos}));
    prepend_to_libpath(join_file($Config{CFX5_IMPI_DIR}, 'lib'));
  }

  export_multiport_conf();
}

=head2 export_multiport_conf

  CFX5::Parallel::MPI::export_multiport_conf('ibmmpi');

  Set and export configuration variables required by multiport.
  For the wrapper a specific MPI implementation can be specified.
  If no implementation is defined, assume the 'stub' library.

=cut

sub export_multiport_conf
{
  my $implementation = shift;
  $implementation = 'stub' unless defined $implementation;

  my $multiport_root = join_file($Config{CFX_TOOLS_ROOT}, 'multiport');

  prepend_to_libpath(join_file($multiport_root, $Config{FLUENTOS}, 'mpi', 'shared'));
  prepend_to_libpath(join_file($multiport_root, 'utilities', $Config{FLUENTOS}));
  prepend_to_libpath(join_file($multiport_root, 'mpi_wrapper', $Config{FLUENTOS}, $implementation));

  CFX5::Config::export_conf('MULTIPORT_ROOT');
}

1;
