xref: /petsc/config/PETSc/options/memAlign.py (revision 7ad1098541f8a490cd032a2f4153a5aee266e4b3)
19d310bb7SBarry Smith#!/usr/bin/env python
29d310bb7SBarry Smithfrom __future__ import generators
39d310bb7SBarry Smithimport user
49d310bb7SBarry Smithimport config.base
59d310bb7SBarry Smith
69d310bb7SBarry Smithclass Configure(config.base.Configure):
79d310bb7SBarry Smith  def __init__(self, framework):
89d310bb7SBarry Smith    config.base.Configure.__init__(self, framework)
99d310bb7SBarry Smith    self.headerPrefix = ''
109d310bb7SBarry Smith    self.substPrefix  = ''
119d310bb7SBarry Smith    return
129d310bb7SBarry Smith
139d310bb7SBarry Smith  def __str1__(self):
149d310bb7SBarry Smith    if not hasattr(self, 'memalign'):
159d310bb7SBarry Smith      return ''
169d310bb7SBarry Smith    return '  Memory alignment: ' + self.memalign + '\n'
179d310bb7SBarry Smith
189d310bb7SBarry Smith  def setupHelp(self, help):
199d310bb7SBarry Smith    import nargs
209d310bb7SBarry Smith    help.addArgument('PETSc', '-with-memalign=<4,8,16,32,64>', nargs.Arg(None, '16', 'Specify alignment of arrays allocated by PETSc'))
219d310bb7SBarry Smith    return
229d310bb7SBarry Smith
239d310bb7SBarry Smith  def setupDependencies(self, framework):
249d310bb7SBarry Smith    config.base.Configure.setupDependencies(self, framework)
259d310bb7SBarry Smith    self.types     = framework.require('config.types', self)
269d310bb7SBarry Smith    self.languages = framework.require('PETSc.options.languages', self)
279d310bb7SBarry Smith    self.compilers = framework.require('config.compilers', self)
289d310bb7SBarry Smith    return
299d310bb7SBarry Smith
309d310bb7SBarry Smith  def configureMemAlign(self):
319d310bb7SBarry Smith    '''Choose alignment'''
329d310bb7SBarry Smith    # Intel/AMD cache lines are 64 bytes, default page sizes are usually 4kB. It would be pretty silly to want that much alignment by default.
339d310bb7SBarry Smith    valid = ['4', '8', '16', '32', '64', '128', '256', '512', '1024', '2048', '4096', '8192']
349d310bb7SBarry Smith    self.memalign = self.framework.argDB['with-memalign']
359d310bb7SBarry Smith    if self.memalign in valid:
369d310bb7SBarry Smith      self.addDefine('MEMALIGN', self.memalign)
379d310bb7SBarry Smith    else:
389d310bb7SBarry Smith      raise RuntimeError('--with-memalign must be in' + str(valid))
39*7ad10985SMatthew G. Knepley    self.logPrint('Memory alignment is ' + self.memalign)
409d310bb7SBarry Smith    return
419d310bb7SBarry Smith
429d310bb7SBarry Smith  def configure(self):
439d310bb7SBarry Smith    self.executeTest(self.configureMemAlign)
449d310bb7SBarry Smith    return
45