/[escript]/trunk/doc/user/execute.tex
ViewVC logotype

Diff of /trunk/doc/user/execute.tex

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2375 by gross, Tue Apr 7 04:41:28 2009 UTC revision 2420 by gross, Thu May 14 02:28:58 2009 UTC
# Line 131  When \MPI is used on more than one proce Line 131  When \MPI is used on more than one proce
131  \escript assumes that an argument of the type \var{int}, \var{float}, \var{str}  \escript assumes that an argument of the type \var{int}, \var{float}, \var{str}
132  and \numarray has an identical value across all processors. All  and \numarray has an identical value across all processors. All
133  values of these types returned by \escript have the same value on all processors.  values of these types returned by \escript have the same value on all processors.
134  If values produced by other modules are used as argument the user has to make sure that  If values produced by other modules are used as arguments the user has to make sure that the argument values are identical on all processors. For instance, the usage of a random number generator to create argument values bears the risk that the value may depend on the processor.
 the value is identical on all processors. For instance, the usage of a random number  
  generator to create a value for argument bears the risk that the value may depend on  
 the processor.  
135    
136  An other case which needs special attention is the usage of files. When reading data  Special attention is required when using files on more then one processor as
137  from a file it advisable to use the \var{'r'} for readable when opened. Keep in mind that  several processors access the file at the same time. Open a file for
138  several scripts will simultaneously access the file. If data are written to a file  reading is safe, however the user has to make sure that the variables which are
139  only one processor must open the file for writing. The function \function{getMPIRankWorld}  set from reading data from files are identical on all processors.
140  which returns the processor id between $0$ and the number of processors  
141  helps to achieve this. The following script writes to the file  When writing data to a file it is important that only one processor is writing to
142    the file at any time. As all values in \escript are global it is sufficient
143    to write values on the processor with \MPI rank $0$ only.
144    The \class{FileWriter} class provides a convenient way to write global data
145    to a simple file.  The following script writes to the file
146  \var{'test.txt'} on the processor with id $0$ only:  \var{'test.txt'} on the processor with id $0$ only:
147  \begin{python}  \begin{python}
148  from esys.escript import *  from esys.escript import *
149  if getMPIRankWorld() == 0 :  f = FileWriter('test.txt')
    f = open('test.txt', 'w')  
    f.write('test message')  
    f.close()  
 \end{python}  
 Another technique is to extend the file name by the processor id to avoid conflicts while  
 writing into a shared file system:  
 \begin{python}  
 from esys.escript import *  
 f = open('test.txt.%s'%getMPIRankWorld(), 'w')  
150  f.write('test message')  f.write('test message')
151  f.close()  f.close()
152  \end{python}  \end{python}
153  creating files with names  It is highly recommendable to use this class rather than the build \function{open}
154  \var{test.txt.0},  function as it will guarantee a script which will run in single processor mode as well as under \MPI.
 \var{test.txt.1},  
 \var{test.txt.2},  
 $\ldots$.  
155    
156  If there is the situation that if execution on one of the processors is throwing an exception,  If there is the situation that on one of the processors is throwing an exception,
157  for instance as opening a file for writing fails, are not made aware of this as \MPI  for instance as opening a file for writing fails, the other processors
158    are not automatically made aware of this as \MPI
159  is not handling exceptions. However, \MPI will terminate the other processes but  is not handling exceptions. However, \MPI will terminate the other processes but
160  may not inform the user of the reason in the obvious way. The user needs to inspect the  may not inform the user of the reason in an obvious way. The user needs to inspect the
161  error output files to identify the exception.  error output files to identify the exception.
   
   
   
   

Legend:
Removed from v.2375  
changed lines
  Added in v.2420

  ViewVC Help
Powered by ViewVC 1.1.26