Commits

Debojyoti Ghosh committed 7dc43d2 Merge

Merged petsc/petsc into master

Comments (0)

Files changed (1210)

 Ethan Coon <ecoon@lanl.gov>                     <ecoon@aeneas>
 Glenn Hammond <glenn.hammond@pnnl.gov>          Glenn Hammond <unknown>
 Hong Zhang <hzhang@mcs.anl.gov>                 hzhang <unknown>
+Hong Zhang (VT) <zhang@vt.edu>
 Jason Sarich <sarich@mcs.anl.gov>               <sarich@24-148-35-133.na.21stcentury.net>
 Jason Sarich <sarich@mcs.anl.gov>               <sarich@Chico.mcs.anl.gov>
 Jed Brown <jed@59A2.org>                        <jed@59A2.org>
 Kris Buschelman <buschelm@mcs.anl.gov>          <Kris@attempt2>
 Kris Buschelman <buschelm@mcs.anl.gov>          <kris@192.168.1.104>
 Lisandro Dalcin <dalcinl@gmail.com>             <dalcinl@trantor.ceride.gov.ar>
+Lois Curfman McInnes <curfman@mcs.anl.gov>      <lois@new-host-2.home>
 Mark Adams <mark.adams@columbia.edu>
 Mark Adams <mark.adams@columbia.edu>            <adams@jaguarpf-login1.ccs.ornl.gov>
 Mark Spiegelman <mspieg@ldea.columbia.edu>      <mspieg@mingus.ldeo.columbia.edu>
 Peter Brune <brune@uchicago.edu>                <emppter@pbrune>
 Peter Brune <brune@mcs.anl.gov>                 <brune@localhost>
 Peter Brune <brune@mcs.anl.gov>                 <prbrune@localhost>
+Richard Tran Mills <rtm@eecs.utk.edu>
 Shri Abhyankar <abhyshr@mcs.anl.gov>
 Stefano Zampini <stefano.zampini@gmail.com>
 Tobin Isaac <tisaac@ices.utexas.edu>

bin/TOPSInstaller.py

 
 
         args.append('--with-shared-libraries=1')
-        args.append('--with-dynamic-loading=1')
         args.append('--with-external-packages-dir='+reply)
         args = multenterbox("Configure options you have selected.", title, None, args)
         if not args: sys.exit()

bin/maint/asterix-test.sh

 # basic sun tests
 ./config/examples/asterix/asterix64-sun.py
 make PETSC_ARCH=asterix64-sun all test
-./config/examples/asterix/asterix64-sun.py --with-shared-libraries=1 --with-dynamic-loading=1 -PETSC_ARCH=asterix64-sun-dynamic
+./config/examples/asterix/asterix64-sun.py --with-shared-libraries=1 -PETSC_ARCH=asterix64-sun-dynamic
 make PETSC_ARCH=asterix64-sun-dynamic all alltests tests_DATAFILESPATH DATAFILESPATH=/home/balay/datafiles
 ./config/examples/asterix/asterix64-sun.py --with-clanguage=cxx -PETSC_ARCH=asterix64-sun-cxx  --with-debugging=0 --with-pic=0 \
 --download-f-blaslapack=1 --download-spooles=1 --download-superlu=1 \
 make PETSC_ARCH=asterix64-sun-cxx all
 make PETSC_ARCH=asterix64-sun-cxx CLINKER=sun-cc shared
 make PETSC_ARCH=asterix64-sun-cxx test
-./config/examples/asterix/asterix64-sun.py --with-shared-libraries=1 --with-dynamic-loading=1 --with-scalar-type=complex --with-clanguage=cxx -PETSC_ARCH=asterix64-sun-complex-dynamic
+./config/examples/asterix/asterix64-sun.py --with-shared-libraries=1 --with-scalar-type=complex --with-clanguage=cxx -PETSC_ARCH=asterix64-sun-complex-dynamic
 make PETSC_ARCH=asterix64-sun-complex-dynamic all
 make PETSC_ARCH=asterix64-sun-complex-dynamic CLINKER=sun-cc shared
 make PETSC_ARCH=asterix64-sun-complex-dynamic test

bin/maint/builddist

 #
 # This script builds the PETSc tar file distribution
 #
-# Usage: builddist petscrepo branch
-# example usage: builddist /sandbox/petsc/petsc.clone maint
+# Usage: builddist petscrepo [branch] [name]
+# example usages:
+#   builddist /sandbox/petsc/petsc.clone balay/foo [petsc-dev-balay-foo.tar.bz]
+#   builddist /sandbox/petsc/petsc.clone master [petsc-dev.tar.bz]
+#   builddist /sandbox/petsc/petsc.clone maint [petsc-3.4.1.tar.bz]
+#   builddist /sandbox/petsc/petsc.clone maint release-snapshot [petsc-release-snapshot.tar.bz]
+#
 # Notes: version info is automatically obtained from include/petscversion.h
 #
 #echo "------- Have you done ALL of the following?? -----------------------------"
 # If version specified on the commandline, set the version
 echo "Starting date: `date`"
 
-if [ $# = 2 ]; then
+if [ $# = 3 ]; then
+  petscrepo=$1
+  branch=$2
+  version=-$3
+elif [ $# = 2 ]; then
   petscrepo=$1
   branch=$2
 elif [ $# = 1 ]; then
 version_date=`date +"%b, %d, %Y"`
 version_git=`git log -1 --pretty=format:%H`
 version_date_git=`git log -1 --pretty=format:%ci`
-if  [ ${version_release} = 0 ]; then
-  if [ "$branch" = "master" ]; then
-    version=-dev
+if [ ${version}foo = foo ]; then
+  if  [ ${version_release} = 0 ]; then
+    if [ "$branch" = "master" ]; then
+      version=-dev
+    else
+      version=-`echo ${branch} | sed s~/~-~g`
+    fi
+  elif [ ${version_release} = 1 ]; then
+    version=-${version_major}.${version_minor}.${version_subminor}
   else
-    version=-$branch
+    echo "Unknown PETSC_VERSION_RELEASE: ${version_release}"
+    exit
   fi
-elif [ ${version_release} = 1 ]; then
-  version=-${version_major}.${version_minor}.${version_subminor}
-else
-  echo "Unknown PETSC_VERSION_RELEASE: ${version_release}"
-  exit
 fi
 echo "Building ~/petsc$version.tar.gz and ~/petsc-lite$version.tar.gz"
 

bin/maint/package-test.sh

 set -x
 ECHO=
 
-OPT1='--with-shared-libraries=1 --with-dynamic-loading=1 --with-debugging=0'
+OPT1='--with-shared-libraries=1 --with-debugging=0'
 OPT2='--with-clanguage=cxx --with-sieve=1 --with-log=0'
 OPT3='--with-scalar-type=complex --with-clanguage=cxx --with-pic=0 --with-log=0'
 

bin/maint/toclapack.sh

 TAR=tar
 
 # Some vars
-FBLASLAPACK=f2cblaslapack-3.4.1.q
+FBLASLAPACK=f2cblaslapack-3.4.2.q
 BIN=${TMP}/bin
 PAC=${TMP}/${FBLASLAPACK}
 BLASDIR=${PAC}/blas

bin/matlab/PetscBagRead.m

    
 function [n, h] = ParsePetscBagDotH
    
-   petscbagh = [GetPetscDir,'/src/sys/bag/bagimpl.h'];
+   petscbagh = [GetPetscDir,'/include/petsc-private/bagimpl.h'];
    fid = fopen(petscbagh,'rt');
    if (fid<0)
       errstr = sprintf('Could not open %s.',petscbagh);

bin/matlab/PetscReadBinaryMatlab.m

 %   This function returns a single struct containing all objects submitted
 %   to the PetscViewerBinaryMatlab viewer.
 
-  matlabHeader = '%$$ '; % string that marks a matlab line for evaluation (could be passed)
+  matlabHeader = ['%$$ '; '#$$ ']; % string that marks a matlab line for evaluation (could be passed)
+  matlabHeaderLen = size(matlabHeader,2);
 
   if (isempty(strfind(filename,'.info')))
      filename = [filename,'.info'];
   while (ischar(str))
 
      % check for output lines that start matlabHeader
-     header = strmatch(matlabHeader,str);
-     if header
-	 str = str(header+length(matlabHeader):end);
+     if strncmp(str,matlabHeader(1,:),matlabHeaderLen) || strncmp(str,matlabHeader(2,:),matlabHeaderLen)
+	 str = str(1+matlabHeaderLen:end);
 
      	 % check for old-style file open/close commands
 	 if strfind(str,'fopen(Set.filename')

bin/processSummary.py

-#!/usr/bin/env python
-import user
-import script
-
-class LogSummarizer(script.Script):
-  transforms = [
-    (', boost::tuples::null_type', ''),
-    ('ALE::pair<ALE::Point, int>', 'Rank'),
-    ('ALE::Sieve<ALE::Point, int, int>', 'Topology'),
-    ('ALE::CoSifter<Topology, ALE::Point, ALE::Point, int>', 'Bundle'),
-    ('ALE::CoSifter<Topology, ALE::Point, ALE::Point, double>', 'Field'),
-    ('ALE::CoSifter<Topology, Rank, ALE::Point, int>', 'RankBundle'),
-    ('ALE::CoSifter<Topology, Rank, ALE::Point, double>', 'RankField'),
-    ('std::less<ALE::Point>', 'lessPoint'),
-    ('std::less<Rank >', 'lessRank'),
-    ('Bundle::trueFunc<ALE::Point>', 'trueFunc'),
-    ('RankField::trueFunc<ALE::Point>', 'trueFunc'),
-    ('Field::trueFunc<ALE::Point>', 'trueFunc'),
-    ('boost::multi_index::composite_key_compare<lessPoint, lessPoint, lessPoint>', 'stdCompare'),
-    ('boost::multi_index::composite_key_compare<lessPoint, std::less<int>, lessPoint>', 'stdCompareInt'),
-    ('boost::multi_index::composite_key_compare<lessPoint, trueFunc, lessPoint>', 'orderCompare'),
-    ('boost::multi_index::composite_key_compare<lessPoint, trueFunc, lessRank>', 'orderRankCompare'),
-    ('ALE::array<ALE::Point>', 'PointArray'),
-    ('ALE::set<ALE::Point>', 'PointSet'),
-    ('std::vector<ALE::Point, std::allocator<ALE::Point> >', 'PointVec'),
-    ('std::set<int, std::less<int>, std::allocator<int> >', 'IntSet'),
-    ('ALE::SifterDef::Arrow<ALE::Point, ALE::Point, ALE::Point>', 'Arrow'),
-    ('ALE::SifterDef::Arrow<ALE::Point, ALE::Point, int>', 'IntArrow'),
-    ('ALE::SifterDef::Arrow<ALE::Point, Rank, ALE::Point>', 'RankArrow'),
-    ('ALE::SifterDef::Arrow<int, ALE::Point, ALE::pair<ALE::Point, ALE::pair<int, int> > >', 'OverlapArrow'),
-    ('ALE::SifterDef::Arrow<ALE::Point, int, ALE::pair<ALE::Point, ALE::pair<int, int> > >', 'FlipOverlapArrow'),
-    ('ALE::SifterDef::Arrow<int, ALE::pair<int, ALE::Point>, ALE::pair<ALE::Point, ALE::pair<int, int> > >', 'BiOverlapArrow'),
-    ('ALE::SifterDef::Arrow<ALE::pair<int, ALE::Point>, int, ALE::pair<ALE::Point, ALE::pair<int, int> > >', 'FlipBiOverlapArrow'),
-    ('ALE::SifterDef::Rec<ALE::Point>', 'Point'),
-    ('ALE::SifterDef::Rec<Rank >', 'RankPoint'),
-    ('ALE::SifterDef::Rec<int>', 'IntPoint'),
-    ('ALE::SifterDef::Rec<ALE::pair<int, ALE::Point> >', 'IPPairPoint'),
-    ('ALE::SieveDef::Rec<ALE::Point, int>', 'Point&Int'),
-    ('ALE::SieveDef::Rec<int, ALE::Point>', 'Int&Point'),
-    ('ALE::SifterDef::RecContainerTraits<ALE::Point, Point >', 'SifterRecTraits'),
-    ('ALE::SifterDef::RecContainerTraits<int, IntPoint >', 'OverlapRecTraits'),
-    ('ALE::SieveDef::RecContainerTraits<ALE::Point, Point&Int >', ' SieveRecTraits'),
-    ('ALE::SifterDef::RecContainer<ALE::Point, Point >', 'SifterRecCon'),
-    ('ALE::SifterDef::RecContainer<Rank, RankPoint >', 'RankRecCon'),
-    ('ALE::SifterDef::RecContainer<int, IntPoint >', 'OverlapRecCon'),
-    ('ALE::SifterDef::RecContainer<ALE::pair<int, ALE::Point>, IPPairPoint >', 'BiOverlapRecCon'),
-    ('ALE::SieveDef::RecContainer<ALE::Point, Point&Int >', 'SieveRecCon'),
-    ('SifterRecTraits::PointSequence', 'SifPointSeq'),
-    ('OverlapRecTraits::PointSequence', 'OvPointSeq'),
-    ('SieveRecTraits::PointSequence', 'SivPointSeq'),
-    ('SieveRecTraits::TwoValueSequence< SieveRecTraits::heightMarkerTag, int>', 'HeightSeq'),
-    ('SieveRecTraits::TwoValueSequence< SieveRecTraits::depthMarkerTag, int>', 'DepthSeq'),
-    ('ALE::RightSequenceDuplicator<ALE::ConeArraySequence<Arrow > >', 'SeqDup'),
-    ('ALE::RightSequenceDuplicator<ALE::ConeArraySequence<IntArrow > >', 'IntSeqDup'),
-    ('ALE::Sifter<ALE::Point, ALE::Point, ALE::Point, orderCompare, SifterRecCon, SifterRecCon >', 'Order'),
-    ('ALE::Sifter<ALE::Point, ALE::Point, ALE::Point, stdCompare, SifterRecCon, SifterRecCon >', 'ReOrder'),
-    ('ALE::Sifter<ALE::Point, Rank, ALE::Point, orderRankCompare, SifterRecCon, RankRecCon >', 'RankOrder'),
-    ('ALE::ASifter<int, ALE::Point, ALE::pair<ALE::Point, ALE::pair<int, int> >, (ALE::SifterDef::ColorMultiplicity)1, boost::multi_index::composite_key_compare<std::less<int>, std::less<ALE::pair<ALE::Point, ALE::pair<int, int> > >, lessPoint>, OverlapRecCon, SifterRecCon >', 'Overlap'),
-    ('ALE::ASifter<ALE::Point, int, ALE::pair<ALE::Point, ALE::pair<int, int> >, (ALE::SifterDef::ColorMultiplicity)1, boost::multi_index::composite_key_compare<lessPoint, std::less<ALE::pair<ALE::Point, ALE::pair<int, int> > >, std::less<int>>, SifterRecCon, OverlapRecCon >', 'FlipOverlap'),
-    ('ALE::ASifter<int, ALE::pair<int, ALE::Point>, ALE::pair<ALE::Point, ALE::pair<int, int> >, (ALE::SifterDef::ColorMultiplicity)1, boost::multi_index::composite_key_compare<std::less<int>, std::less<ALE::pair<ALE::Point, ALE::pair<int, int> > >, std::less<ALE::pair<int, ALE::Point> >>, OverlapRecCon, BiOverlapRecCon >', 'BiOverlap'),
-    ('ALE::ASifter<ALE::pair<int, ALE::Point>, int, ALE::pair<ALE::Point, ALE::pair<int, int> >, (ALE::SifterDef::ColorMultiplicity)1, boost::multi_index::composite_key_compare<std::less<ALE::pair<int, ALE::Point> >, std::less<ALE::pair<ALE::Point, ALE::pair<int, int> > >, std::less<int>>, BiOverlapRecCon, OverlapRecCon >', 'FlipBiOverlap'),
-    ('ALE::ASifter<ALE::Point, ALE::Point, int, (ALE::SifterDef::ColorMultiplicity)1, stdCompareInt, SieveRecCon, SieveRecCon >::traits::coneSequence', 'ConeSeq'),
-    ('ALE::ASifter<ALE::Point, ALE::Point, int, (ALE::SifterDef::ColorMultiplicity)1, stdCompareInt, SieveRecCon, SieveRecCon >::traits::supportSequence', 'SuppSeq'),
-    ('ALE::ASifter<ALE::Point, ALE::Point, ALE::Point, (ALE::SifterDef::ColorMultiplicity)1, stdCompare, SifterRecCon, SifterRecCon >::traits::coneSequence', 'OrderFusionCone'),
-    ('ALE::ASifter<ALE::Point, ALE::Point, ALE::Point, (ALE::SifterDef::ColorMultiplicity)1, stdCompare, SifterRecCon, SifterRecCon >::traits::supportSequence', 'OrderFusionSupp'),
-    ('ALE::ASifter<ALE::Point, ALE::Point, ALE::Point, (ALE::SifterDef::ColorMultiplicity)1, orderCompare, SifterRecCon, SifterRecCon >::traits::coneSequence', 'OrderCone'),
-    ('ALE::ASifter<ALE::Point, ALE::Point, ALE::Point, (ALE::SifterDef::ColorMultiplicity)1, orderCompare, SifterRecCon, SifterRecCon >::traits::supportSequence', 'OrderSupp'),
-    ('BiOverlap::traits::coneSequence', 'BiOverlapCone'),
-    ('BiOverlap::traits::supportSequence', 'BiOverlapSupp'),
-    ('FlipBiOverlap::traits::coneSequence', 'FlipBiOverlapCone'),
-    ('FlipBiOverlap::traits::supportSequence', 'FlipBiOverlapSupp'),
-    ('ALE::Flip<Order >', 'FlipOrder'),
-    ('ALE::Flip<ReOrder >', 'FlipReOrder'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<Arrow > > > >', 'bArrow'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<IntArrow > > > >', 'bIntArrow'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<RankArrow > > > >', 'bRankArrow'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<OverlapArrow > > > >', 'bOverlapArrow'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<FlipOverlapArrow > > > >', 'bFlipOverlapArrow'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<BiOverlapArrow > > > >', 'bBiOverlapArrow'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<FlipBiOverlapArrow > > > >', 'bFlipBiOverlapArrow'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<Point > >', 'bPoint'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<Point&Int > > > > >', 'bIntPoint'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<RankPoint > >', 'bRankPoint'),
-    ('boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<OverlapPoint > > > >', 'bOverlapPoint'),
-    ('boost::multi_index::detail::copy_map_entry<bArrow >', 'bArrowCopy'),
-    ('boost::multi_index::detail::copy_map_entry<bPoint >', 'bPointCopy'),
-    ('std::_Rb_tree_node<ALE::Point>', 'tPoint')
-    ]
-
-  removes = [
-    'Registered event',
-    'boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<ALE::SifterDef::Arrow<ALE::Point, ALE::Point, int> > > > >:',
-    'boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<ALE::SieveDef::Rec<ALE::Point, int> > > > > >:',
-    'boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<ALE::SifterDef::Arrow<ALE::Point, ALE::Point, ALE::Point> > > > >:',
-    'boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<ALE::SifterDef::Rec<ALE::Point> > >:',
-    'boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<ALE::SifterDef::Arrow<ALE::Point, ALE::pair<ALE::Point, int>, ALE::Point> > > > >:',
-    'boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<ALE::SifterDef::Rec<ALE::pair<ALE::Point, int> > > >:',
-    'boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<ALE::SifterDef::Rec<int> > >',
-    'boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<ALE::SifterDef::Rec<ALE::pair<int, ALE::Point> > > >',
-    'std::_Rb_tree_node<ALE::Point>:',
-    'Obj:std::set<std::string',
-    'std::set<std::string'
-    ]
-
-  def setupHelp(self, help):
-    help = script.Script.setupHelp(self, help)
-    #help.addArgument('LogSummarizer', '-', nargs.ArgBool(None, 0, 'Print this help message', isTemporary = 1), ignoreDuplicates = 1)
-    return help
-
-  def filter(self, line):
-    for r in LogSummarizer.removes:
-      if line.startswith(r):
-        return ''
-    return line
-
-  def transform(self, line):
-    '''We could try to pick out just the event lines'''
-    for longName, shortName in LogSummarizer.transforms:
-      line = line.replace(longName, shortName)
-    return line
-
-  def process(self, inF, outF):
-    for line in inF.readlines():
-      line = self.filter(line)
-      line = self.transform(line)
-      outF.write(line)
-    return
-
-  def run(self):
-    import sys
-
-    self.setup()
-    self.process(sys.stdin, sys.stdout)
-    return
-
-if __name__ == '__main__':
-  LogSummarizer().run()

bin/win32fe/win32fe.exe

Binary file modified.

bin/win32fe/win32feutils.dll

Binary file modified.
+#!/usr/bin/env python
+
+import os
+from distutils.sysconfig import parse_makefile
+import sys
+import logging
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'config'))
+from cmakegen import Mistakes, stripsplit, AUTODIRS, SKIPDIRS
+from cmakegen import defaultdict # collections.defaultdict, with fallback for python-2.4
+
+PKGS = 'sys vec mat dm ksp snes ts'.split()
+LANGS = dict(c='C', cxx='C', cu='CU', F='F')
+
+try:
+    all([True, True])
+except NameError:               # needs python-2.5
+    def all(iterable):
+        for i in iterable:
+            if not i:
+                return False
+        return True
+
+try:
+    os.path.relpath             # needs python-2.6
+except AttributeError:
+    def _relpath(path, start=os.path.curdir):
+        """Return a relative version of a path"""
+
+        from os.path import curdir, abspath, commonprefix, sep, pardir, join
+        if not path:
+            raise ValueError("no path specified")
+
+        start_list = [x for x in abspath(start).split(sep) if x]
+        path_list = [x for x in abspath(path).split(sep) if x]
+
+        # Work out how much of the filepath is shared by start and path.
+        i = len(commonprefix([start_list, path_list]))
+
+        rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+        if not rel_list:
+            return curdir
+        return join(*rel_list)
+    os.path.relpath = _relpath
+
+class debuglogger(object):
+    def __init__(self, log):
+        self._log = log
+
+    def write(self, string):
+        self._log.debug(string)
+
+class Petsc(object):
+    def __init__(self, petsc_dir=None, petsc_arch=None, verbose=False):
+        if petsc_dir is None:
+            petsc_dir = os.environ.get('PETSC_DIR')
+            if petsc_dir is None:
+                try:
+                    petsc_dir = parse_makefile(os.path.join('conf', 'petscvariables')).get('PETSC_DIR')
+                finally:
+                    if petsc_dir is None:
+                        raise RuntimeError('Could not determine PETSC_DIR, please set in environment')
+        if petsc_arch is None:
+            petsc_arch = os.environ.get('PETSC_ARCH')
+            if petsc_arch is None:
+                try:
+                    petsc_arch = parse_makefile(os.path.join(petsc_dir, 'conf', 'petscvariables')).get('PETSC_ARCH')
+                finally:
+                    if petsc_arch is None:
+                        raise RuntimeError('Could not determine PETSC_ARCH, please set in environment')
+        self.petsc_dir = petsc_dir
+        self.petsc_arch = petsc_arch
+        self.read_conf()
+        logging.basicConfig(filename=self.arch_path('conf', 'gmake.log'), level=logging.DEBUG)
+        self.log = logging.getLogger('gmakegen')
+        self.mistakes = Mistakes(debuglogger(self.log), verbose=verbose)
+        self.gendeps = []
+
+    def arch_path(self, *args):
+        return os.path.join(self.petsc_dir, self.petsc_arch, *args)
+
+    def read_conf(self):
+        self.conf = dict()
+        for line in open(self.arch_path('include', 'petscconf.h')):
+            if line.startswith('#define '):
+                define = line[len('#define '):]
+                space = define.find(' ')
+                key = define[:space]
+                val = define[space+1:]
+                self.conf[key] = val
+        self.conf.update(parse_makefile(self.arch_path('conf', 'petscvariables')))
+        self.have_fortran = int(self.conf.get('PETSC_HAVE_FORTRAN', '0'))
+
+    def inconf(self, key, val):
+        if key in ['package', 'function', 'define']:
+            return self.conf.get(val)
+        elif key == 'precision':
+            return val == self.conf['PETSC_PRECISION']
+        elif key == 'scalar':
+            return val == self.conf['PETSC_SCALAR']
+        elif key == 'language':
+            return val == self.conf['PETSC_LANGUAGE']
+        raise RuntimeError('Unknown conf check: %s %s' % (key, val))
+
+    def relpath(self, root, src):
+        return os.path.relpath(os.path.join(root, src), self.petsc_dir)
+
+    def get_sources(self, makevars):
+        """Return dict {lang: list_of_source_files}"""
+        source = dict()
+        for lang, sourcelang in LANGS.items():
+            source[lang] = [f for f in makevars.get('SOURCE'+sourcelang,'').split() if f.endswith(lang)]
+        return source
+
+    def gen_pkg(self, pkg):
+        pkgsrcs = dict()
+        for lang in LANGS:
+            pkgsrcs[lang] = []
+        for root, dirs, files in os.walk(os.path.join(self.petsc_dir, 'src', pkg)):
+            makefile = os.path.join(root,'makefile')
+            if not os.path.exists(makefile):
+                dirs[:] = []
+                continue
+            mklines = open(makefile)
+            conditions = set(tuple(stripsplit(line)) for line in mklines if line.startswith('#requires'))
+            mklines.close()
+            if not all(self.inconf(key, val) for key, val in conditions):
+                dirs[:] = []
+                continue
+            makevars = parse_makefile(makefile)
+            mdirs = makevars.get('DIRS','').split() # Directories specified in the makefile
+            self.mistakes.compareDirLists(root, mdirs, dirs) # diagnostic output to find unused directories
+            candidates = set(mdirs).union(AUTODIRS).difference(SKIPDIRS)
+            dirs[:] = list(candidates.intersection(dirs))
+            allsource = []
+            def mkrel(src):
+                return self.relpath(root, src)
+            source = self.get_sources(makevars)
+            for lang, s in source.items():
+                pkgsrcs[lang] += map(mkrel, s)
+                allsource += s
+            self.mistakes.compareSourceLists(root, allsource, files) # Diagnostic output about unused source files
+            self.gendeps.append(self.relpath(root, 'makefile'))
+        return pkgsrcs
+
+    def gen_gnumake(self, fd):
+        def write(stem, srcs):
+            fd.write('%s :=\n' % stem)
+            for lang in LANGS:
+                fd.write('%(stem)s.%(lang)s := %(srcs)s\n' % dict(stem=stem, lang=lang, srcs=' '.join(srcs[lang])))
+                fd.write('%(stem)s += $(%(stem)s.%(lang)s)\n' % dict(stem=stem, lang=lang))
+        for pkg in PKGS:
+            srcs = self.gen_pkg(pkg)
+            write('srcs-' + pkg, srcs)
+        return self.gendeps
+
+    def gen_ninja(self, fd):
+        libobjs = []
+        for pkg in PKGS:
+            srcs = self.gen_pkg(pkg)
+            for lang in LANGS:
+                for src in srcs[lang]:
+                    obj = '$objdir/%s.o' % src
+                    fd.write('build %(obj)s : %(lang)s_COMPILE %(src)s\n' % dict(obj=obj, lang=lang.upper(), src=os.path.join(self.petsc_dir,src)))
+                    libobjs.append(obj)
+        fd.write('\n')
+        fd.write('build $libdir/libpetsc.so : %s_LINK_SHARED %s\n\n' % ('CF'[self.have_fortran], ' '.join(libobjs)))
+        fd.write('build petsc : phony || $libdir/libpetsc.so\n\n')
+
+    def summary(self):
+        self.mistakes.summary()
+
+def WriteGnuMake(petsc):
+    arch_files = petsc.arch_path('conf', 'files')
+    fd = open(arch_files, 'w')
+    gendeps = petsc.gen_gnumake(fd)
+    fd.write('\n')
+    fd.write('# Dependency to regenerate this file\n')
+    fd.write('%s : %s %s\n' % (os.path.relpath(arch_files, petsc.petsc_dir),
+                               os.path.relpath(__file__, petsc.petsc_dir),
+                               ' '.join(gendeps)))
+    fd.write('\n')
+    fd.write('# Dummy dependencies in case makefiles are removed\n')
+    fd.write(''.join([dep + ':\n' for dep in gendeps]))
+    fd.close()
+
+def WriteNinja(petsc):
+    conf = dict()
+    parse_makefile(os.path.join(petsc.petsc_dir, 'conf', 'variables'), conf)
+    parse_makefile(petsc.arch_path('conf', 'petscvariables'), conf)
+    build_ninja = petsc.arch_path('build.ninja')
+    fd = open(build_ninja, 'w')
+    fd.write('objdir = obj-ninja\n')
+    fd.write('libdir = lib\n')
+    fd.write('c_compile = %(PCC)s\n' % conf)
+    fd.write('c_flags = %(PETSC_CC_INCLUDES)s %(PCC_FLAGS)s %(CCPPFLAGS)s\n' % conf)
+    fd.write('c_link = %(PCC_LINKER)s\n' % conf)
+    fd.write('c_link_flags = %(PCC_LINKER_FLAGS)s\n' % conf)
+    if petsc.have_fortran:
+        fd.write('f_compile = %(FC)s\n' % conf)
+        fd.write('f_flags = %(PETSC_FC_INCLUDES)s %(FC_FLAGS)s %(FCPPFLAGS)s\n' % conf)
+        fd.write('f_link = %(FC_LINKER)s\n' % conf)
+        fd.write('f_link_flags = %(FC_LINKER_FLAGS)s\n' % conf)
+    fd.write('petsc_external_lib = %(PETSC_EXTERNAL_LIB_BASIC)s\n' % conf)
+    fd.write('python = %(PYTHON)s\n' % conf)
+    fd.write('\n')
+    fd.write('rule C_COMPILE\n'
+             '  command = $c_compile -MMD -MF $out.d $c_flags -c $in -o $out\n'
+             '  description = CC $out\n'
+             '  depfile = $out.d\n'
+             # '  deps = gcc\n') # 'gcc' is default, 'msvc' only recognized by newer versions of ninja
+             '\n')
+    fd.write('rule C_LINK_SHARED\n'
+             '  command = $c_link $c_link_flags -shared -o $out $in $petsc_external_lib\n'
+             '  description = CLINK_SHARED $out\n'
+             '\n')
+    if petsc.have_fortran:
+        fd.write('rule F_COMPILE\n'
+                 '  command = $f_compile -MMD -MF $out.d $f_flags -c $in -o $out\n'
+                 '  description = FC $out\n'