00001 __copyright__ = """
00002 Copyright 2008 Sean Ross-Ross
00003 """
00004 __license__ = """
00005 This file is part of SLIMpy .
00006
00007 SLIMpy is free software: you can redistribute it and/or modify
00008 it under the terms of the GNU Lesser General Public License as published by
00009 the Free Software Foundation, either version 3 of the License, or
00010 (at your option) any later version.
00011
00012 SLIMpy is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 GNU Lesser General Public License for more details.
00016
00017 You should have received a copy of the GNU Lesser General Public License
00018 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00019 """
00020
00021
00022 from slimpy_base.api.Plugins.slim2rsf.rsfContainer import rsf_data_container
00023 from slimpy_base.api.Plugins.slim2rsf.mpi_factory import rsf_mpi_factory
00024 from os.path import isfile
00025 from slimpy_base.Core.Interface.node import Node
00026 from slimpy_base.Core.Command.Drivers.Unix_Pipes import gethostname
00027 class MPI_ScalarMethods( object ):
00028 def __call__(self,*args,**kw):
00029 raise Exception( 'rsf mpi has no scalar methods' )
00030
00031 class rsf_mpidata_container( rsf_data_container ):
00032 '''
00033
00034 '''
00035 suffix = ".xsf"
00036 psuffix = ".vpl"
00037 name = "rsfmpi"
00038
00039 _scalar_methods = MPI_ScalarMethods( )
00040 sfFactory = rsf_mpi_factory()
00041
00042 def __init__(self, data=None , parameters=None, command=None, tmp=None ):
00043
00044
00045 self._command = command
00046 self._node_map = None
00047 self._contained = None
00048 rsf_data_container.__init__(self, data=data ,
00049 parameters=parameters,
00050 command=command,
00051 tmp=tmp,
00052 target_node='localhost' )
00053
00054
00055 @classmethod
00056 def isCompatibleWith( cls, obj ):
00057 '''
00058 statict method to determine if 'obj' is an rsf meta header file
00059 @param obj:
00060 @type obj: any object that would be
00061 contained in a datacontainer class
00062 '''
00063
00064 obj = str(obj)
00065
00066 if obj.endswith( cls.suffix ):
00067 if not isfile( obj ):
00068 raise Exception, "the file %s can not be found" %( obj )
00069 return True
00070 if isfile( obj + cls.suffix ):
00071 return True
00072
00073
00074 def node_copy(self, node_name):
00075 if node_name == 'localhost' or node_name == gethostname( ):
00076 return
00077 else:
00078 raise Exception('can not copy meta header to local nodes')
00079
00080 def has_built_meta_info(self):
00081 return self._contained is not None
00082
00083 def expand_meta( self ):
00084 """
00085 Returns an list of all the subcontainers in this one.
00086 """
00087
00088 if self._contained is None:
00089
00090 self._contained = []
00091 if self._node_map is None:
00092 converter = self.get_converter( self._command.tag )
00093 self._node_map = converter.gen_node_map( self.params, self._command )
00094 metaspace = self.params['metaspace']
00095
00096 tmp = self.istmp()
00097 self_id = Node(self).id
00098
00099 siter = zip( self._node_map , metaspace.ravel( ) )
00100 for (data, nodelist), space in siter:
00101
00102 dc = rsf_data_container( data, space ,
00103 target_node = nodelist,
00104 tmp=tmp )
00105 self._contained.append( dc )
00106
00107 id = Node(dc).id
00108
00109 self.add_referent(id)
00110 dc.add_referrers( self_id )
00111
00112
00113 return self._contained
00114
00115