File: Batch.pl

package info (click to toggle)
dmrgpp 6.06-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 113,900 kB
  • sloc: cpp: 80,986; perl: 14,772; ansic: 2,923; makefile: 83; sh: 17
file content (77 lines) | stat: -rwxr-xr-x 1,437 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl
#PBS -N mpi
#PBS -q batch
#PBS -l nodes=2:ppn=16
#PBS -l walltime=1:00:00
#PBS -l vmem=90gb

use strict;
use warnings;
use utf8;

chdir $ENV{"PBS_O_WORKDIR"};

#date
my $np=4;
my $nodefile = $ENV{"PBS_NODEFILE"};
my $h = getHostString($nodefile, $np);

#my $realCmd = "hostname";
my $realCmd = "./internode 4";

my $command = "LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/usr/lib64/openmpi/lib ";
$command .= "/usr/lib64/openmpi/bin/mpiexec -n $np -host \"$h\"  $realCmd";
system("$command");

sub getHostString
{
	my ($file, $mpiJobs) = @_;

	my %h;
	my $firstNode;
	open(FILE, "<", "$file") or die "$0: Cannot open $file : $!\n";
	while (<FILE>) {
		chomp;
		next if (/^#/ or $_ eq "");
		my $f = $_;
		$firstNode = $f;
		if (!defined($h{"$f"})) {
			$h{"$f"} = 1;
		} else {
			++$h{"$f"};
		}
	}

	close(FILE);

	my $nodes = scalar(keys %h);
	die "$0: Nodes $nodes must be a multiple of mpiJobs $mpiJobs\n" if ($mpiJobs % $nodes != 0);

	die "$0: No nodes!\n" if ($nodes == 0 or !defined($firstNode));
	my $ppn = $h{"$firstNode"};
	my $repeat = $mpiJobs/$nodes;
	return getHostString2($repeat, \%h);
}

sub getHostString2
{
	my ($repeat, $h) = @_;
	my $firstcall = 1;
	my $str = "";
	for (my $i = 0; $i < $repeat; ++$i) {
		foreach my $key (sort keys %$h) {
			my $n = $h->{"$key"};
			next if ($n == 0);
			if ($firstcall) {
				$firstcall = 0;
			} else {
				$str .= ",";
			}

			$str .= "$key";
		}
	}

	return $str;
}