Changeset 517


Ignore:
Timestamp:
Mar 9, 2012 3:10:26 PM (10 years ago)
Author:
toby
Message:

make sure that texture is initialized for multiprocessing

Location:
MPbranch
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • MPbranch/GSASIIlattice.py

    r432 r517  
    10191019   
    10201020def Glnh(Start,SHCoef,psi,gam,SamSym):
     1021    # Start is not used
    10211022    import pytexture as ptx
    10221023    RSQPI = 0.5641895835478
    10231024    SQ2 = 1.414213562373
    1024 
    1025     if Start:
    1026         ptx.pyqlmninit()
    1027         Start = False
     1025    InitTexture()
    10281026    Fln = np.zeros(len(SHCoef))
    10291027    for i,term in enumerate(SHCoef):
     
    10421040
    10431041def Flnh(Start,SHCoef,phi,beta,SGData):
     1042    # Start is not used
    10441043    import pytexture as ptx
    10451044   
     
    10471046    RSQPI = 0.5641895835478
    10481047    SQ2 = 1.414213562373
    1049 
    1050     if Start:
    1051         ptx.pyqlmninit()
    1052         Start = False
     1048    InitTexture()
    10531049    Fln = np.zeros(len(SHCoef))
    10541050    for i,term in enumerate(SHCoef):
     
    14471443            if H not in hklN:
    14481444                print H,' missing from hkl from GSASII'
    1449        
    1450        
    1451    
     1445
     1446TextureInit = False
     1447def InitTexture():
     1448    '''A routine to initialize the texture routines only once'''
     1449    global TextureInit
     1450    if not TextureInit:
     1451        import pytexture as ptx
     1452        ptx.pyqlmninit()
     1453        TextureInit = True   
    14521454
    14531455if __name__ == '__main__':
  • MPbranch/GSASIIpath.py

    r280 r517  
    1 # determine a binary path for the pyd files based on the host OS and the python version, 
    2 # path is relative to location of the script that is called as well as this file
    3 # this must be imported before anything that imports any .pyd/.so file for GSASII
     1''' determine a binary path for the pyd files based on the host OS and the python version,
     2path is relative to location of the script that is called as well as this file
     3this must be imported before anything that imports any .pyd/.so file for GSASII
     4
     5also determine if GSAS-II is being run interactively'''
     6
    47import os.path as ospath
    58import sys
    69import platform
     10
     11# Find the name of the main routine and if we are running interactively (true if GSASII.py)
     12import __main__
     13GSAS2interactive = False
     14try:
     15    if ospath.split(__main__.__file__)[1].lower() == "gsasii.py":
     16        GSAS2interactive = True
     17except:
     18   pass
     19
     20# define the path to where GSAS-II source files are found from the location of
     21# the current file
     22path2GSAS2 = ospath.dirname(ospath.realpath(__file__))
     23
    724bindir = None
    825if sys.platform == "win32":
     
    1835    else:
    1936        bindir = 'binlinux%d.%d' % sys.version_info[0:2]
    20 for loc in sys.path[0],ospath.split(__file__)[0]:
     37for loc in sys.path[0],path2GSAS2:
    2138    if bindir:
    2239        if ospath.exists(ospath.join(loc,bindir)) and ospath.join(loc,bindir) not in sys.path:
  • MPbranch/GSASIIplot.py

    r496 r517  
    11571157    '''Plot 3D mustrain/size/preferred orientation figure. In this instance data is for a phase
    11581158    '''
     1159    # Start is not used -- fix later
    11591160   
    11601161    PatternId = G2frame.PatternId
     
    11621163    SGData = generalData['SGData']
    11631164    SGLaue = SGData['SGLaue']
    1164     if Start:                   #initialize the spherical harmonics qlmn arrays
    1165         ptx.pyqlmninit()
    1166         Start = False
     1165    G2lat.InitTexture()
    11671166    MuStrKeys = G2spc.MustrainNames(SGData)
    11681167    cell = generalData['Cell'][1:]
  • MPbranch/GSASIIstruct.py

    r514 r517  
    4141    '''
    4242    Controls = {'deriv type':'analytic Hessian','max cyc':3,
    43                 'max Hprocess':1,
    44                 'max Rprocess':2,
     43                'max Hprocess':2,
     44                'max Rprocess':1,
    4545                'min dM/M':0.0001,'shift factor':1.}
    4646    file = open(GPXfile,'rb')
     
    23382338
    23392339def getPowderProfile(parmDict,x,varylist,Histogram,Phases,calcControls,pawleyLookup):               
    2340     if (calcControls['max Hprocess'] <= 1 and calcControls['max Rprocess'] > 1:
     2340    if calcControls['max Hprocess'] <= 1 and calcControls['max Rprocess'] > 1:
    23412341        mpPool = mp.Pool()
     2342        #print 'multiprocess function call'
     2343    #else:
     2344        #print 'single thread function call'
    23422345    hId = Histogram['hId']
    23432346    hfx = ':%d:'%(hId)
     
    23882391            calcControls['max Rprocess'] == 1 or
    23892392            mp.cpu_count() < 2 or len(refList) <  2 * chunk):
    2390             print 'single thread function',hId,len(refList)
    23912393            res = ComputeReflectionProfile(
    23922394                (0,refList,x,Phase,calcControls,wave,G,g,GB,Vst,
     
    23962398            yc[iBeg:iFin] += yct
    23972399        else:
    2398             print 'multiprocess function',hId,len(refList)
    23992400            argList = []
    24002401            for i in range(0,len(refList),chunk):
     
    26042605       
    26052606def getPowderProfileDerv(parmDict,x,varylist,Histogram,Phases,calcControls,pawleyLookup):   
    2606     if (calcControls['max Hprocess'] <= 1 and calcControls['max Rprocess'] > 1:
     2607    if calcControls['max Hprocess'] <= 1 and calcControls['max Rprocess'] > 1:
    26072608        mpPool = mp.Pool()
     2609        #print 'mp derivs'
     2610    #else:
     2611        #print 'single thread derivs'
    26082612    # create a list of dependent variables and set up a dictionary to hold their derivatives
    26092613    dependentVars = G2mv.GetDependentVars()
     
    26672671            calcControls['max Rprocess'] == 1 or
    26682672            mp.cpu_count() < 2 or len(refList) <  2 * chunk):
    2669             print 'single thread derivs'
    26702673            TdepDerivDict, TdMdv, iBegO, iFinO = ComputeReflectionDerivative(
    26712674                (0,refList,x,dependentVars,varylist,dFdvDict,
     
    26762679                depDerivDict[j] += TdepDerivDict[j]
    26772680        else:
    2678             print 'multiprocess derivs'
    26792681            argList = []
    26802682            for iref in range(0,len(refList),chunk):
     
    27202722
    27212723def ComputePowderHessian(args):
     2724    G2lat.InitTexture()     #initialize fortran arrays for spherical harmonics
    27222725    Histogram,parmdict,varylist,Phases,calcControls,pawleyLookup = args
    27232726    hId = Histogram['hId']
     
    27972800
    27982801def ComputePowderProfile(args):
     2802    G2lat.InitTexture()     #initialize fortran arrays for spherical harmonics
    27992803    Histogram,parmdict,varylist,Phases,calcControls,pawleyLookup,histkey = args
    28002804    hId = Histogram['hId']
     
    28742878                )
    28752879    if MaxProcess > 1:
    2876         mpPool = mp.Pool()
     2880        mpPool = mp.Pool(1)
    28772881        for (xB,xF,ycSect,ybSect,RL,histkey
    28782882             ) in mpPool.imap_unordered(ComputePowderProfile,argList):
     
    28872891            Histogram['sumwYo'] = np.sum(w[xB:xF]*y[xB:xF]**2)
    28882892            sumwYo += Histogram['sumwYo']
    2889            
    28902893            yc[xB:xF] = ycSect
    28912894            yb[xB:xF] = ybSect
     
    29342937                   
    29352938def Refine(GPXfile,dlg):
    2936     import pytexture as ptx
    2937     ptx.pyqlmninit()            #initialize fortran arrays for spherical harmonics
    2938    
     2939    G2lat.InitTexture()     #initialize fortran arrays for spherical harmonics
    29392940    ShowBanner()
    29402941    varyList = []
     
    30803081
    30813082def SeqRefine(GPXfile,dlg):
    3082     import pytexture as ptx
    3083     ptx.pyqlmninit()            #initialize fortran arrays for spherical harmonics
    3084    
     3083    G2lat.InitTexture()     #initialize fortran arrays for spherical harmonics
    30853084    ShowBanner()
    30863085    print ' Sequential Refinement'
Note: See TracChangeset for help on using the changeset viewer.