=head1 NAME

  CFX5::Parallel::Reqs::impi_winsmpd - Check for Intel MPI SMPD

This prerequisite performs the checks required for Intel MPI
parallel on Windows, where the Simple Multi-Purpose Daemon (SMPD) needs
to be referenced in the registry.

=cut

package CFX5::Parallel::Reqs::impi_winsmpd;

use CFX5::Parallel::Reqs::Base;
push @ISA, qw(CFX5::Parallel::Reqs::Base);

use CFX5::Config qw(%Config);
use CFX5::Output qw(:all);
use CFX5::FileTests;
use CFX5::PkgLoader qw(cfx5_require);

use strict;

sub smpd_binary {
  my $self=shift;
  return '' unless $Config{windows_nt};

  cfx5_require('CFX5::Win32::Registry') or return '';

  my $binary = CFX5::Win32::Registry::registry_get('Software/Intel/MPI/SMPD/binary');
  return $binary;
}

sub setup {
  my $self=shift;
  my $workdir=shift;

  unless ($Config{windows_nt}) {
    internal_error("Can only perform Intel MPI SPMD checks on Windows");
  }

  my $binary = $self->smpd_binary();

  # SMPD binary isn't defined: Error
  unless (defined $binary) {
    _error("No SMPD binary was defined in the registry for Intel MPI Parallel.  Either use the \"cfx5parallel -install-impi-service\" command to set up the Intel MPI service or install Intel MPI using the ANSYS Installer.");
    return '';
  }

  # SMPD binary defined: Make sure it exists and is executable
  unless (CFX5::FileTests::execfile($binary, "The SMPD binary for Intel MPI Parallel $binary was defined in the registry but")) {
    return '';
  }

  1;
}

1;
