File: ompi_wrapper_script.in

package info (click to toggle)
openmpi 3.1.3-11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,572 kB
  • sloc: ansic: 628,972; f90: 17,993; makefile: 13,761; sh: 7,051; java: 6,360; perl: 3,215; cpp: 2,225; python: 1,350; lex: 988; fortran: 52; tcl: 12
file content (240 lines) | stat: -rw-r--r-- 7,552 bytes parent folder | download | duplicates (3)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#! @PERL@ -w
# -*- perl -*-
#
# Note that we use an interpreter value ("PERL") from configure
# because even "#!/usr/bin/env perl" to all systems (e.g., NetBSD).
#
# Copyright (c) 2009-2012 Cisco Systems, Inc.  All rights reserved.
# Copyright (c) 2010      Oracle and/or its affiliates.  All rights reserved.
# Copyright (c) 2013      Sandia National Laboratories.  All rights reserved.
# Copyright (c) 2016      IBM Corporation.  All rights reserved.
# Copyright (c) 2016      Research Organization for Information Science
#                         and Technology (RIST). All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#

use File::Basename;
use File::Spec::Functions;

my $includedir = "@OMPI_WRAPPER_INCLUDEDIR@";
my $libdir = "@OMPI_WRAPPER_LIBDIR@";

# obey the OPAL_DESTDIR environment variable
if (exists($ENV{'OPAL_DESTDIR'})
  && defined($ENV{'OPAL_DESTDIR'})
  && (length($ENV{'OPAL_DESTDIR'}) > 0)) {
    my $ddir = $ENV{'OPAL_DESTDIR'};

    $includedir = catdir($ddir, $includedir);
    $libdir = catdir($ddir, $libdir);
}

my $CC = "@WRAPPER_CC@";
my $CXX = "@CXX@";
my $FC = "@FC@";
my $extra_cppflags = "@OMPI_WRAPPER_EXTRA_CPPFLAGS@";
my $extra_cflags = "@OMPI_WRAPPER_EXTRA_CFLAGS@";
my $extra_cflags_prefix = "@OMPI_WRAPPER_EXTRA_CFLAGS_PREFIX@";
my $extra_cxxflags = "@OMPI_WRAPPER_EXTRA_CXXFLAGS@";
my $extra_cxxflags_prefix = "@OMPI_WRAPPER_EXTRA_CXXFLAGS_PREFIX@";
my $extra_fcflags = "@OMPI_WRAPPER_EXTRA_FCFLAGS@";
my $extra_fcflags_prefix = "@OMPI_WRAPPER_EXTRA_FCFLAGS_PREFIX@";
my $extra_ldflags = "@OMPI_PKG_CONFIG_LDFLAGS@";
my $extra_libs = "@OMPI_WRAPPER_EXTRA_LIBS@";
my $cxx_lib = "@OMPI_WRAPPER_CXX_LIB@";
my $fc_module_flag = "@OMPI_FC_MODULE_FLAG@";
my $dynamic_lib_suffix = "@OPAL_DYN_LIB_SUFFIX@";
my $fortran_libs = "@OMPI_FORTRAN_USEMPIF08_LIB@ @OMPI_FORTRAN_USEMPI_LIB@";
my $ompi_libmpi_name = "@OMPI_LIBMPI_NAME@";

# Someone might want to fix for windows
my $include_flag = "-I";
my $libdir_flag = "-L";

my $lang = "none";
my $comp = ""; # this is a sentinal from configure
my $preproc_flags = $include_flag . $includedir;
my $comp_flags = "";
my $comp_flags_prefix = "";
my $linker_flags = $libdir_flag . $libdir . " " . $extra_ldflags;
# Note that per https://svn.open-mpi.org/trac/ompi/ticket/3422, we
# intentionally only link in the MPI libraries (ORTE, OPAL, etc. are
# pulled in implicitly) because we intend MPI applications to only use
# the MPI API.
my $libs = "-l".$ompi_libmpi_name." " . $extra_libs;
my $libs_static = "-l".$ompi_libmpi_name." -lopen-rte -lopen-pal " . $extra_libs;

my $have_dynamic = 0;
if (-e $libdir . "/lib".$ompi_libmpi_name."." . $dynamic_lib_suffix) {
    $have_dynamic = 1;
}
my $have_static = 0;
if (-e $libdir . "/lib".$ompi_libmpi_name.".a") {
    $have_static = 1;
}

# run flags through regex to fix directories...
$extra_cppflags =~ s/\$\{includedir\}/$includedir/g;
$extra_cflags =~ s/\$\{includedir\}/$includedir/g;
$extra_cflags_prefix =~ s/\$\{includedir\}/$includedir/g;
$extra_cxxflags =~ s/\$\{includedir\}/$includedir/g;
$extra_cxxflags_prefix =~ s/\$\{includedir\}/$includedir/g;
$extra_fcflags =~ s/\$\{includedir\}/$includedir/g;
$extra_fcflags_prefix =~ s/\$\{includedir\}/$includedir/g;
$extra_ldflags =~ s/\$\{libdir\}/$libdir/g;
$extra_libs =~ s/\$\{libdir\}/$libdir/g;

sub check_env {
    my $envvar = shift;
    my $str = shift;

    foreach my $var (("OMPI_MPI", "OMPI_")) {
        my $testvar = $var . $envvar;
        if (exists($ENV{$testvar})) {
            $str = $ENV{$testvar};
            return $str;
        }
    }

    return $str;
}


if (basename($0) eq "mpicc") {
    $lang = "C";
    $comp = check_env("CC", $CC);
    $preproc_flags .= " " . $extra_cppflags;
    $comp_flags = $extra_cflags;
    $comp_flags_prefix = $extra_cflags_prefix;
    # no special libs for C
} elsif (basename($0) eq "mpic++" || basename($0) eq "mpiCC" || basename($0) eq "mpicxx") {
    $lang = "C++";
    $comp = check_env("CXX", $CXX);
    $preproc_flags .= " " . $extra_cppflags;
    $comp_flags = $extra_cxxflags;
    $comp_flags_prefix = $extra_cxxflags_prefix;
    $libs = $cxx_lib . " " . $libs;
}
# mpifort is now preferred; mpif77/mpif90 are legacy names
elsif (basename($0) eq "mpifort" ||
         basename($0) eq "mpif77" || basename($0) eq "mpif90") {
    $lang = "Fortran";
    $comp = check_env("FC", $FC);
    # no extra includes for Fortran.
    $comp_flags = $extra_fcflags;
    $comp_flags_prefix = $extra_fcflags_prefix;
    $libs = $fortran_libs . " -l".$ompi_libmpi_name."_mpifh " . $libs;
}

if ($lang eq "none") {
    print "Could not determine requested language\n";
    exit 1;
}
if ($comp eq "") {
    print "Unfortunately, this installation of Open MPI was not compiled with\n";
    print $lang . " support.  As such, the " . $lang . " compiler is non-functional.\n";
    exit 1;
}

# figure out what user wants
my @args = @ARGV;
my $want_preproc = 1;
my $want_compile = 1;
my $want_link = 1;
my $want_pmpi = 0;
my $dry_run = 0;
my $disable_flags = 1;
my $real_flag = 0;
my @appargs = ();
my $want_static = 0;

while (scalar(@args) > 0) {
    my $arg = shift(@args);

    if ($arg eq "-showme" || $arg eq "--showme") {
        $dry_run = 1;
    } elsif ($arg eq "-lpmpi") {
        $want_pmpi = 1;
    } elsif ($arg eq "--openmpi:linkall") {
        $libs = $libs_static;
    } else {
        if ($arg eq "-c") {
            $want_link = 0;
            $real_flag = 1;
        } elsif ($arg eq "-E" || $arg eq "-M") {
            $want_compile = 0;
            $want_link = 0;
            $real_flag = 1;
        } elsif ($arg eq "-S") {
            $want_link = 0;
            $real_flag = 1;
        } elsif ($arg eq "-static" ||
                  $arg eq "--static" ||
                  $arg eq "-Bstatic" ||
                  $arg eq "-Wl,-static" ||
                  $arg eq "-Wl,--static" ||
                  $arg eq "-Wl,-Bstatic") {
            $want_static = 1;
            $real_flag = 1;
        } elsif ($arg eq "-dynamic" ||
                  $arg eq "--dynamic" ||
                  $arg eq "-Bdynamic" ||
                  $arg eq "-Wl,-dynamic" ||
                  $arg eq "-Wl,--dynamic" ||
                  $arg eq "-Wl,-Bdynamic") {
            $want_static = 0;
            $real_flag = 1;
        } elsif ($arg =~ /^-.*/) {
            $real_flag = 1;
        } else {
            $real_flag = 1;
            $disable_flags = 0;
        }
        push(@appargs, $arg);
    }
}

if ($disable_flags == 1 && !($dry_run == 1 && $real_flag == 0)) {
    $want_preproc = $want_compile = $want_link = 0;
}

if ($want_static == 1 || $have_dynamic == 0) {
    $libs = $libs_static;
}

my @exec_argv = ();

# assemble command
push(@exec_argv, split(' ', $comp));
# Per tickets https://svn.open-mpi.org/trac/ompi/ticket/2474, and
# https://svn.open-mpi.org/trac/ompi/ticket/2201, construct command
# with some system arguments before user arguments and some after.
if ($want_compile == 1) {
    push(@exec_argv, split(' ', $comp_flags_prefix));
}
push(@exec_argv, @appargs);
if ($want_preproc == 1) {
    push(@exec_argv, split(' ', $preproc_flags));
}
if ($want_compile == 1) {
    push(@exec_argv, split(' ', $comp_flags));
}
if ($want_link == 1) {
    push(@exec_argv, split(' ', $linker_flags));
    push(@exec_argv, split(' ', $libs));
}

if ($dry_run == 1) {
    print join(" ", @exec_argv) . "\n";
    exit 0;
}

$cmd = shift(@exec_argv);
if ($real_flag == 0) {
    @exec_argv = ();
}
exec($cmd, (@exec_argv)) || die "Could not exec " . $exec_argv[0] . ": $!\n";