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