=head1 NAME

  CFX5::Parallel::Reqs::phst - Phst generator for CFX-5 parallel

=cut

package CFX5::Parallel::Reqs::phst;

# lots of stuff in common with the 'hst' file writer
use CFX5::Parallel::Reqs::hst;
push @ISA, qw(CFX5::Parallel::Reqs::hst);

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

use CFX5::PkgLoader qw(cfx5_require);

use strict;

=head3 write_phst

The C<phst> file has the same format as the C<hst> files used
previously by the parallel solver, but the number of processes
indicates the number of partitions to run on a given host, and the
relative speed is ignored.  It is used by the new PVM solver to
specify exactly which processes to run.

=cut

sub speed_entry {
  my $self=shift;
  my $h=shift;
  if ($h->use_cfx5remote() and not $h->is_win32()) {
    # if we're using the remote script, the speed line gets replaced
    # by the executable
    return $self->SUPER::exec_entry($h);
  } else {
    return '';
  }
}
sub exec_entry {
  my $self=shift;
  my $h=shift;
  if ($h->use_cfx5remote() and not $h->is_win32()) {
    # if we're using the remote script, that gets put in place of the
    # executable
    my $remote=$h->fill_in_exec($h->cfx5remote_path());
    #my $remote='/home3/cfdasm/tmp/dome';
    return $remote;
  } else {
    return $self->SUPER::exec_entry($h);
  }
}

sub write_phst {
  my $self=shift;
  my $file=shift;

  my @hl=$self->ppe()->partitions_master_first();

  return $self->write_hst_file($file, @hl);
}

=head4 setup

=cut

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

  # we always remove and re-write
  $workdir->remove_file('phst') if $workdir->have_file('phst');
  my $file=$workdir->creatable_file('phst');
  unless ($self->write_phst($file)) {
    _error("Error writing phst file: $!");
    return undef;
  }
  return $file;
}

1;
