Esempio n. 1
0
File: generic.py Progetto: pf4d/issm
	def BuildQueueScript(self,dirname,modelname,solution,io_gather,isvalgrind,isgprof,isdakota,isoceancoupling):    # {{{

		executable='issm.exe';
		if isdakota:
			version=IssmConfig('_DAKOTA_VERSION_')[0:2]
			version=float(version)
			if version>=6:
				executable='issm_dakota.exe'
		if isoceancoupling:
			executable='issm_ocean.exe'

		#write queuing script 
		if not m.ispc():

			fid=open(modelname+'.queue','w')
			fid.write('#!/bin/sh\n')
			if not isvalgrind:
				if self.interactive: 
					if IssmConfig('_HAVE_MPI_')[0]:
						fid.write('mpiexec -np %i %s/%s %s %s/%s %s ' % (self.np,self.codepath,executable,solution,self.executionpath,dirname,modelname))
					else:
						fid.write('%s/%s %s %s/%s %s ' % (self.codepath,executable,solution,self.executionpath,dirname,modelname))
				else:
					if IssmConfig('_HAVE_MPI_')[0]:
						fid.write('mpiexec -np %i %s/%s %s %s/%s %s 2> %s.errlog >%s.outlog ' % (self.np,self.codepath,executable,solution,self.executionpath,dirname,modelname,modelname,modelname))
					else:
						fid.write('%s/%s %s %s/%s %s 2> %s.errlog >%s.outlog ' % (self.codepath,executable,solution,self.executionpath,dirname,modelname,modelname,modelname))
			elif isgprof:
				fid.write('\n gprof %s/%s gmon.out > %s.performance' % (self.codepath,executable,modelname))
			else:
				#Add --gen-suppressions=all to get suppression lines
				fid.write('LD_PRELOAD=%s \\\n' % self.valgrindlib)
				if IssmConfig('_HAVE_MPI_')[0]:
					fid.write('mpiexec -np %i %s --leak-check=full --suppressions=%s %s/%s %s %s/%s %s 2> %s.errlog >%s.outlog ' % \
							(self.np,self.valgrind,self.valgrindsup,self.codepath,executable,solution,self.executionpath,dirname,modelname,modelname,modelname))
				else:	
					fid.write('%s --leak-check=full --suppressions=%s %s/%s %s %s/%s %s 2> %s.errlog >%s.outlog ' % \
							(self.valgrind,self.valgrindsup,self.codepath,executable,solution,self.executionpath,dirname,modelname,modelname,modelname))

			if not io_gather:    #concatenate the output files:
				fid.write('\ncat %s.outbin.* > %s.outbin' % (modelname,modelname))
			fid.close()

		else:    # Windows

			fid=open(modelname+'.bat','w')
			fid.write('@echo off\n')
			if self.interactive:
				fid.write('"%s/%s" %s "%s/%s" %s ' % (self.codepath,executable,solution,self.executionpath,dirname,modelname))
			else:
				fid.write('"%s/%s" %s "%s/%s" %s 2> %s.errlog >%s.outlog' % \
					(self.codepath,executable,solution,self.executionpath,dirname,modelname,modelname,modelname))
			fid.close()

		#in interactive mode, create a run file, and errlog and outlog file
		if self.interactive:
			fid=open(modelname+'.errlog','w')
			fid.close()
			fid=open(modelname+'.outlog','w')
			fid.close()
Esempio n. 2
0
File: generic.py Progetto: pf4d/issm
	def Download(self,dirname,filelist):     # {{{

		if m.ispc():
			#do nothing
			return

		#copy files from cluster to current directory
		directory='%s/%s/' % (self.executionpath,dirname)
		issmscpin(self.name,self.login,self.port,directory,filelist)
Esempio n. 3
0
def issmdir():
    """
	ISSMDIR - Get ISSM_DIR environment variable
 
	   Usage:
	      ISSM_DIR=issmdir()
	"""

    if not m.ispc():
        ISSM_DIR = os.environ['ISSM_DIR']
    else:
        ISSM_DIR = os.environ['ISSM_DIR_WIN']
        if m.strcmpi(ISSM_DIR[-1], '/') or m.strcmpi(ISSM_DIR[-1], '\\'):
            ISSM_DIR = ISSM_DIR[:-1]  #shave off the last '/'

    if not ISSM_DIR:
        raise RuntimeError(
            "issmdir error message: 'ISSM_DIR' environment variable is empty! You should define ISSM_DIR in your .cshrc or .bashrc!"
        )

    return ISSM_DIR
Esempio n. 4
0
File: generic.py Progetto: pf4d/issm
	def BuildKrigingQueueScript(self,modelname,solution,io_gather,isvalgrind,isgprof):    # {{{

		#write queuing script 
		if not m.ispc():

			fid=open(modelname+'.queue','w')
			fid.write('#!/bin/sh\n')
			if not isvalgrind:
				if self.interactive:
					fid.write('mpiexec -np %i %s/kriging.exe %s/%s %s ' % (self.np,self.codepath,self.executionpath,modelname,modelname))
				else:
					fid.write('mpiexec -np %i %s/kriging.exe %s/%s %s 2> %s.errlog >%s.outlog ' % (self.np,self.codepath,self.executionpath,modelname,modelname,modelname,modelname))
			elif isgprof:
				fid.write('\n gprof %s/kriging.exe gmon.out > %s.performance' & (self.codepath,modelname))
			else:
				#Add --gen-suppressions=all to get suppression lines
				fid.write('LD_PRELOAD=%s \\\n' % self.valgrindlib)
				fid.write('mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s/%s %s 2> %s.errlog >%s.outlog ' % \
					(self.np,self.valgrind,self.valgrindsup,self.codepath,self.executionpath,modelname,modelname,modelname,modelname))
			if not io_gather:    #concatenate the output files:
				fid.write('\ncat %s.outbin.* > %s.outbin' % (modelname,modelname))
			fid.close()

		else:    # Windows

			fid=open(modelname+'.bat','w')
			fid.write('@echo off\n')
			if self.interactive:
				fid.write('"%s/issm.exe" %s "%s/%s" %s ' % (self.codepath,solution,self.executionpath,modelname,modelname))
			else:
				fid.write('"%s/issm.exe" %s "%s/%s" %s 2> %s.errlog >%s.outlog' % \
					(self.codepath,solution,self.executionpath,modelname,modelname,modelname,modelname))
			fid.close()

		#in interactive mode, create a run file, and errlog and outlog file
		if self.interactive:
			fid=open(modelname+'.errlog','w')
			fid.close()
			fid=open(modelname+'.outlog','w')
			fid.close()
Esempio n. 5
0
def issmscpout(host, path, login, port, packages):
    """
	ISSMSCPOUT send packages to a host, using scp on unix, and pscp on windows
 
	   usage: issmscpout(host,path,packages)
	"""

    #get hostname
    hostname = gethostname()

    #if hostname and host are the same, do a simple copy

    if m.strcmpi(host, hostname):
        for package in packages:
            here = os.getcwd()
            os.chdir(path)
            try:
                os.remove(package)
            except OSError as e:
                pass
            subprocess.call('ln -s %s %s' %
                            (os.path.join(here, package), path),
                            shell=True)
            os.chdir(here)
    else:
        if m.ispc():
            #use the putty project pscp.exe: it should be in the path.

            #get ISSM_DIR variable
            if 'ISSM_DIR_WIN' in os.environ:
                ISSM_DIR = os.environ['ISSM_DIR_WIN'][1:-2]
            else:
                raise OSError(
                    "issmscpout error message: could not find ISSM_DIR_WIN environment variable."
                )

            username = input('Username: (quoted string) ')
            key = input('Key: (quoted string) ')

            for package in packages:
                try:
                    subprocess.check_call(
                        '%s/externalpackages/ssh/pscp.exe -l "%s" -pw "%s" %s %s:%s'
                        % (ISSM_DIR, username, key, package, host, path),
                        shell=True)
                except CalledProcessError as e:
                    raise CalledProcessError(
                        "issmscpout error message: could not call putty pscp.")

        else:
            #just use standard unix scp
            #create string of packages being sent
            string = ''
            for package in packages:
                string += ' ' + package
            string += ' '

            if port:
                subprocess.call('scp -P %d %s %s@localhost:%s' %
                                (port, string, login, path),
                                shell=True)
            else:
                subprocess.call('scp %s %s@%s:%s' %
                                (string, login, host, path),
                                shell=True)
Esempio n. 6
0
File: issmssh.py Progetto: pf4d/issm
def issmssh(host, login, port, command):
    """
	ISSMSSH - wrapper for OS independent ssh command.
 
	   usage: 
	      issmssh(host,command)
	"""

    #first get hostname
    hostname = gethostname()

    #if same as host, just run the command.
    if m.strcmpi(host, hostname):
        subprocess.call(command, shell=True)
    else:
        if m.ispc():
            #use the putty project plink.exe: it should be in the path.

            #get ISSM_DIR variable
            if 'ISSM_DIR_WIN' in os.environ:
                ISSM_DIR = os.environ['ISSM_DIR_WIN'][1:-2]
            else:
                raise OSError(
                    "issmssh error message: could not find ISSM_DIR_WIN environment variable."
                )

            username = input('Username: (quoted string) ')
            key = input('Key: (quoted string) ')

            subprocess.call(
                '%s/externalpackages/ssh/plink.exe -ssh -l "%s" -pw "%s" %s "%s"'
                % (ISSM_DIR, username, key, host, command),
                shell=True)

        else:
            #just use standard unix ssh
            if port:
                subprocess.call('ssh -l %s -p %d localhost "%s"' %
                                (login, port, command),
                                shell=True)
            else:
                subprocess.call('ssh -l %s %s "%s"' % (login, host, command),
                                shell=True)

    # The following code was added to fix:
    # "IOError: [Errno 35] Resource temporarily unavailable"
    # on the Mac when trying to display md after the solution.
    # (from http://code.google.com/p/robotframework/issues/detail?id=995)

    # Make FreeBSD use blocking I/O like other platforms
    import sys
    import fcntl
    from os import O_NONBLOCK

    fd = sys.stdin.fileno()
    flags = fcntl.fcntl(fd, fcntl.F_GETFL)
    fcntl.fcntl(fd, fcntl.F_SETFL, flags & ~O_NONBLOCK)

    fd = sys.stdout.fileno()
    flags = fcntl.fcntl(fd, fcntl.F_GETFL)
    fcntl.fcntl(fd, fcntl.F_SETFL, flags & ~O_NONBLOCK)
Esempio n. 7
0
def issmscpin(host, login, port, path, packages):
    """
	ISSMSCPIN get packages from host, using scp on unix, and pscp on windows
 
	   usage: issmscpin(host,packages,path)
	"""

    #first get hostname
    hostname = gethostname()

    #first be sure packages are not in the current directory, this could conflict with pscp on windows.
    #remove warnings in case the files do not exist
    for package in packages:
        try:
            os.remove(package)
        except OSError as e:
            pass

    #if hostname and host are the same, do a simple copy
    if m.strcmpi(hostname, host):

        for package in packages:
            try:
                shutil.copy(os.path.join(path, package),
                            os.getcwd())  #keep going, even if success=0
            except OSError as e:
                pass

    else:

        if m.ispc():
            #use the putty project pscp.exe: it should be in the path.

            #get ISSM_DIR variable
            if 'ISSM_DIR_WIN' in os.environ:
                ISSM_DIR = os.environ['ISSM_DIR_WIN'][1:-2]
            else:
                raise OSError(
                    "issmscpin error message: could not find ISSM_DIR_WIN environment variable."
                )

            username = raw_input('Username: (quoted string) ')
            key = raw_input('Key: (quoted string) ')

            for package in packages:
                try:
                    subprocess.check_call(
                        '%s/externalpackages/ssh/pscp.exe -l "%s" -pw "%s" %s:%s %s'
                        % (ISSM_DIR, username, key, host,
                           os.path.join(path, package), os.getcwd()),
                        shell=True)
                except CalledProcessError as e:
                    raise CalledProcessError(
                        "issmscpin error message: could not call putty pscp.")

        else:
            #just use standard unix scp
            #string to copy multiple files using scp:
            string = '\{' + ','.join([str(x) for x in packages]) + '\}'

            if port:
                subprocess.call(
                    'scp -P %d %s@localhost:%s %s/. ' %
                    (port, login, os.path.join(path, string), os.getcwd()),
                    shell=True)
            else:
                subprocess.call(
                    'scp %s@%s:%s %s/.' %
                    (login, host, os.path.join(path, string), os.getcwd()),
                    shell=True)

            #check scp worked
            for package in packages:
                if not os.path.exists(os.path.join('.', package)):
                    raise OSError(
                        "issmscpin error message: could not call scp on *nix system."
                    )