File: mptopcom.rules

package info (click to toggle)
polymake 4.12-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 35,992 kB
  • sloc: cpp: 168,768; perl: 43,375; javascript: 31,575; ansic: 3,007; java: 2,654; python: 633; sh: 268; xml: 117; makefile: 61
file content (123 lines) | stat: -rw-r--r-- 4,502 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#  Copyright (c) 1997-2024
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------

CREDIT mptopcom
   mptopcom is a software developed at TU Berlin and Hokkaido University for
   computing triangulations of point configurations in parallel.
   Copyright by Charles Jordan, Michael Joswig, Lars Kastner.
   https://polymake.org/mptopcom

custom $mptopcom;

custom $mpirun;

CONFIGURE {
   $mptopcom =~ s{(?<=\S)$}{/mptopcom1};
   my $path=find_program($mptopcom, "mptopcom1", { 
      prompt => "the `mptopcom1' program from the mptopcom package", 
   }) or return;
   my $version = `echo bla | $mptopcom --version 2>&1`;
   if($version !~ m/mptopcom version/){
      die <<"---";
Your version of mptopcom is not supported anymore. Please upgrade.
---
   }
   find_program($mpirun, "mpirun", { prompt => "`mpirun' to call mptopcom's parallel version" });
   ($mptopcom) = $path =~ $directory_re;
}

# @category Triangulations, subdivisions and volume
# Use [[wiki:external_software#mptopcom|mptopcom]] for computing triangulations of point configurations in parallel.
label mptopcom

    
# @category Triangulations, subdivisions and volume
# Computes triangulations of a point configuration.
# @param Matrix points as rows.
# @param Array<Array<Int>> generators of group acting on the points.
# @option Bool regular compute only regular triangulations.
# @option Bool fine compute only fine triangulations.
# @return Array<Pair<Array<Set<Int>>, Vector<Int>>> Array of pairs of the form (Triangulation, GKZ vector)
user_function mptopcom1($ ;  Array<Array<Int>>, { regular=>0, fine=>0 }) {
   my ($A, $G, $options) = @_;
   my $cmd = "$mptopcom/mptopcom1";
   return call_mptopcom($cmd, $A, $G, $options);
}

# @category Triangulations, subdivisions and volume
# Computes triangulations of a point configuration.
# @param Matrix points as rows.
# @param Array<Array<Int>> generators of group acting on the points.
# @option Bool regular compute only regular triangulations.
# @option Bool fine compute only fine triangulations.
# @option Int np number of slots for parallel computation.
# @return Array<Pair<Array<Set<Int>>, Vector<Int>>> Array of pairs of the form (Triangulation, GKZ vector)
user_function mptopcom($ ;  Array<Array<Int>>, { regular=>0, fine=>0, np=>3 }) {
   my ($A, $G, $options) = @_;
   my $np = $options->{np};
   $mpirun or die "mpirun not found.\n";
   my $cmd = "$mpirun --oversubscribe -np $np $mptopcom/mptopcom";
   return call_mptopcom($cmd, $A, $G, $options);
}

sub build_mptopcom_command {
   my ($cmd, $options) = @_;
   my $result = $cmd;
   if ($options->{regular}){
      $result .= " --regular";
   }
   if ($options->{fine}){
      $result .= " -F";
   }
   unless ($DebugLevel) {
      $result .= " 2>/dev/null";
   }
   return $result;
}

sub decompose_line {
   my ($line) = @_;
   my ($triang, $gkz) = $line =~ m/(\{\{.*\}\})\]\s*gkz: (\[[^\]]*\])/;
   $triang =~ s/\{/\[/g;
   $triang =~ s/\}/\]/g;
   return new Pair<Array<Set<Int>>, Vector<Int>>(new Array<Set<Int>>(eval $triang), new Vector<Int>(eval $gkz));
}

sub call_mptopcom {
   my ($cmd, $A, $G, $options) = @_;
   my $input = new TempTextFile;
   print $input "[[", join("],[", map(join(",", @$_), @$A)) . "]]\n";
   if (defined($G)) {
      print $input "[[", join("],[", map(join(",", @$_), @$G)) . "]]\n";
   }
   my $mptopcom_command = build_mptopcom_command($cmd, $options) . " < $input";
   if ($Verbose::external) {
        dbg_print( "running mptopcom: $mptopcom_command" );
    }
   open my $output,  "$mptopcom_command |"
     or die "can't start $cmd: $!\n";
   my @result;
   while (my $line = <$output>) {
      push @result, decompose_line($line);
   }
   return new Array<Pair<Array<Set<Int>>, Vector<Int>>>(\@result);
}

# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End: