pymtt
 All Classes Namespaces Files Functions Variables Groups
MPIVersion.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2016-2018 Intel, Inc. All rights reserved.
4 # $COPYRIGHT$
5 #
6 # Additional copyrights may follow
7 #
8 # $HEADER$
9 #
10 
11 import os
12 import sys
13 from BaseMTTUtility import *
14 import shlex
15 
16 ## @addtogroup Utilities
17 # @{
18 # @section MPIVersion
19 # Identify the name and version of MPI in-use
20 # @}
22  def __init__(self):
23  BaseMTTUtility.__init__(self)
24  self.options = {}
25  return
26 
27  def print_name(self):
28  return "MPIVersion"
29 
30  def print_options(self, testDef, prefix):
31  lines = testDef.printOptions(self.options)
32  for line in lines:
33  print(prefix + line)
34  return
35 
36  def execute(self, log, testDef):
37 
38  version_str = self.get_version_string(testDef)
39 
40  if version_str is None:
41  log['name'] = 'None'
42  log['version'] = 'Unknown'
43  return
44 
45  name = None
46  version = None
47 
48  # Open MPI
49  # Example Output:
50  # Open MPI v1.10.2, package: Open MPI abuild@ip-172-31-24-182.us-west-2.compute.internal Distribution, ident: 1.10.2, repo rev: v1.10.1-145-g799148f, Jan 21, 2016
51  if 'Open MPI' in version_str:
52  name = 'Open MPI'
53  version = version_str.split('Open MPI v')[1].split(', ')[0]
54 
55  # MVAPICH2
56  # Example Output:
57  # MVAPICH2 Version : 2.1
58  # MVAPICH2 Release date : Fri Apr 03 20:00:00 EDT 2015
59  # MVAPICH2 Device : ch3:mrail
60  # MVAPICH2 configure : --prefix=/opt/ohpc/pub/mpi/mvapich2-gnu-ohpc/2.1 --enable-cxx --enable-g=dbg --with-device=ch3:mrail --enable-fast=O3
61  # MVAPICH2 CC : gcc -g -O3
62  # MVAPICH2 CXX : g++ -g -O3
63  # MVAPICH2 F77 : gfortran -L/lib -L/lib -g -O3
64  # MVAPICH2 FC : gfortran -g -O3
65  elif 'MVAPICH2' in version_str:
66  name = 'MVAPICH2'
67  version = version_str.split('MVAPICH2 Version')[1].split(':')[1].split("'")[0].split("\\t")[1]
68  # Intel MPI
69  # Example Output:
70  # Intel(R) MPI Library 5.1.3 for Linux* OS
71  elif 'Intel' in version_str:
72  name = 'Intel MPI'
73  version = version_str.split('Intel(R) MPI Library ')[1].split(' ')[0]
74 
75  elif 'CRAY MPICH' in version_str:
76  name = 'CRAY MPICH'
77  version = version_str.split('CRAY MPICH version ')[1].split(' ')[0]
78 
79  # record the result
80  log['name'] = str(name)
81  log['version'] = str(version)
82  return
83 
84  def get_version_string(self, testDef):
85  os.chdir(testDef.options['scratchdir'])
86 
87  try:
88  fh = open("mpi_get_version.c", "r")
89  fh.close()
90  except IOError:
91  fh = open("mpi_get_version.c", "w")
92  fh.write("""
93 /* This program is automatically generated by MPIVersion.py
94  * of MPI Testing Tool (MTT). Any changes you make here may
95  * get lost!
96  * Copyrights and licenses of this file are the same as for the MTT.
97  */
98 #include <mpi.h>
99 #include <stdio.h>
100 int main(int argc, char **argv) {
101  char version[3000];
102  int resultlen;
103  MPI_Get_library_version(version, &resultlen);
104  printf("%s\\n", version);
105  return 0;
106 }""")
107  fh.close()
108  status, _, _, _ = testDef.execmd.execute(None, shlex.split('mpicc -o mpi_get_version mpi_get_version.c'), testDef)
109  if 0 != status:
110  status, _, _, _ = testDef.execmd.execute(None, shlex.split('cc -o mpi_get_version mpi_get_version.c'), testDef)
111  if 0 != status:
112  os.chdir("..")
113  return None
114 
115  status, stdout, _, _ = testDef.execmd.execute(None, shlex.split('sh -c "mpiexec ./mpi_get_version |uniq -c"'), testDef)
116  if 0 != status:
117  status, stdout, _, _ = testDef.execmd.execute(None, shlex.split('sh -c "aprun ./mpi_get_version |uniq -c"'), testDef)
118  if 0 != status:
119  status, stdout, _, _ = testDef.execmd.execute(None, shlex.split('sh -c "./mpi_get_version |uniq -c"'), testDef)
120  if 0 != status:
121  os.chdir("..")
122  return None
123 
124  os.chdir("..")
125 
126  return "\n".join(stdout)