=head1 NAME

  CFX5::Parallel::Reqs::mpich_winmpid - Check for MPICH MPID

This prerequisite does the checks required for MPICH distributed
parallel on Windows, where we need to have registered a user ID and
installed the MPID daemon.

Unfortunately, we can't check the MPID on slave boxes, but we can do
it on the master host.

=cut

package CFX5::Parallel::Reqs::mpich_winmpid;

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

use CFX5::Config qw(%Config);
use CFX5::Output qw(:all);

use CFX5::PkgLoader qw(cfx5_require);

use strict;

sub have_mpiregister {
  my $self=shift;
  return defined $self->registered_user();
}

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

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

  my $account=CFX5::Win32::Registry::registry_get('Software/MPICH/account');
  return $account;
}

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

  unless ($Config{windows_nt}) {
    internal_error("Can only set up the MPId information on Windows");
  }

  unless ($self->have_mpiregister()) {
    # if there's no info, just die.  Don't try to prompt, as that'll
    # fail under the SM.  XXX add the GUI location in the SM.
    _error("No user information has been registered for MPICH distributed parallel runs.  You must use the \"cfx5parallel -register-mpich-user\" command to register user information for MPICH distributed parallel.");
    return '';
  }

  # OK, we have a user.  XXX We also need the mpid service.  This one
  # we might be able to install if it's not there.  For now, just let
  # the solver give an error.

  1;
}

1;
