Index: /anuga_work/production/wollongong_2006/parallel_api.py
===================================================================
--- /anuga_work/production/wollongong_2006/parallel_api.py	(revision 3584)
+++ /anuga_work/production/wollongong_2006/parallel_api.py	(revision 3585)
@@ -1,3 +1,58 @@
 """Trying to lump parallel stuff into simpler interface
 
+
 """
+
+# Parallelism
+import pypar   # The Python-MPI interface
+from anuga_parallel.pmesh_divide  import pmesh_divide_metis
+from anuga_parallel.build_submesh import build_submesh
+from anuga_parallel.build_local   import build_local_mesh
+from anuga_parallel.build_commun  import send_submesh, rec_submesh, extract_hostmesh
+from anuga_parallel.parallel_shallow_water import Parallel_Domain
+
+
+#------------------------------------------------------------------------------
+# Read in processor information
+#------------------------------------------------------------------------------
+
+numprocs = pypar.size()
+myid = pypar.rank()
+processor_name = pypar.Get_processor_name()
+print 'I am processor %d of %d on node %s' %(myid, numprocs, processor_name)
+
+
+
+
+def distribute_mesh(domain):
+
+    numprocs = pypar.size()
+
+    
+    # Subdivide the mesh
+    print 'Subdivide mesh'
+    nodes, triangles, boundary, triangles_per_proc, quantities = \
+           pmesh_divide_metis(domain, numprocs)
+
+    # Build the mesh that should be assigned to each processor,
+    # this includes ghost nodes and the communicaiton pattern
+    print 'Build submeshes'    
+    submesh = build_submesh(nodes, triangles, boundary,\
+                            quantities, triangles_per_proc)
+
+    # Send the mesh partition to the appropriate processor
+    print 'Distribute submeshes'        
+    for p in range(1, numprocs):
+      send_submesh(submesh, triangles_per_proc, p)
+
+    # Build the local mesh for processor 0
+    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \
+              extract_hostmesh(submesh, triangles_per_proc)
+
+    # Return stuff
+    return points, vertices, boundary, quantities, \
+           ghost_recv_dict, full_send_dict
+    
+
+
+
Index: /anuga_work/production/wollongong_2006/run_flagstaff.py
===================================================================
--- /anuga_work/production/wollongong_2006/run_flagstaff.py	(revision 3584)
+++ /anuga_work/production/wollongong_2006/run_flagstaff.py	(revision 3585)
@@ -54,11 +54,4 @@
 
 
-#------------------------------------------------------------------------------
-# Preparation of topographic data
-#
-# Convert ASC 2 DEM 2 PTS using source data and store result in source data
-#------------------------------------------------------------------------------
-
-max_area = project.base_resolution
 if myid == 0:
     
@@ -72,4 +65,5 @@
     print 'Generate mesh'
     # Generate basic mesh
+    max_area = project.base_resolution
     mesh = create_mesh_from_regions(project.bounding_polygon,
                                     boundary_tags=project.boundary_tags,
Index: /anuga_work/production/wollongong_2006/run_flagstaff_parallel_api.py
===================================================================
--- /anuga_work/production/wollongong_2006/run_flagstaff_parallel_api.py	(revision 3584)
+++ /anuga_work/production/wollongong_2006/run_flagstaff_parallel_api.py	(revision 3585)
@@ -31,34 +31,13 @@
 from anuga.pmesh.mesh import importUngenerateFile, Segment
 
+from anuga.caching import cache
+
 # Parallelism
-import pypar   # The Python-MPI interface
-from anuga_parallel.pmesh_divide  import pmesh_divide_metis
-from anuga_parallel.build_submesh import build_submesh
-from anuga_parallel.build_local   import build_local_mesh
-from anuga_parallel.build_commun  import send_submesh, rec_submesh, extract_hostmesh
-from anuga_parallel.parallel_shallow_water import Parallel_Domain
-
+from parallel_api import *
 
 # Application specific imports
 import project
 
-
-#------------------------------------------------------------------------------
-# Read in processor information
-#------------------------------------------------------------------------------
-
-numprocs = pypar.size()
-myid = pypar.rank()
-processor_name = pypar.Get_processor_name()
-print 'I am processor %d of %d on node %s' %(myid, numprocs, processor_name)
-
-
-#------------------------------------------------------------------------------
-# Preparation of topographic data
-#
-# Convert ASC 2 DEM 2 PTS using source data and store result in source data
-#------------------------------------------------------------------------------
-
-max_area = project.base_resolution
+# Sequential part
 if myid == 0:
     
@@ -69,11 +48,15 @@
     #--------------------------------------------------------------------------
 
-
     print 'Generate mesh'
     # Generate basic mesh
-    mesh = create_mesh_from_regions(project.bounding_polygon,
-                                    boundary_tags=project.boundary_tags,
-                                    maximum_triangle_area=max_area,
-                                    interior_regions=project.interior_regions)
+    max_area = project.base_resolution
+
+    
+    mesh = cache(create_mesh_from_regions,
+                 project.bounding_polygon,
+                 {'boundary_tags': project.boundary_tags,
+                  'maximum_triangle_area':max_area,
+                  'interior_regions': project.interior_regions},
+                 verbose=True)
     
     # Add buildings that will bind to a Reflective boundary
@@ -94,30 +77,37 @@
     print domain.statistics()
 
+    domain.set_name(project.basename)
+    domain.set_datadir(project.outputdir)    
+
+
+    #------------------------------------------------------------------------------
+    # Setup initial conditions
+    #------------------------------------------------------------------------------
+    domain.set_quantity('stage', project.initial_sealevel)
+    domain.set_quantity('friction', 0.03)    
     domain.set_quantity('elevation', 
                         filename=project.demname + '.pts',
                         use_cache=True,
-                        verbose=True)    
+                        verbose=True)
 
 
-    # Subdivide the mesh
-    print 'Subdivide mesh'
-    nodes, triangles, boundary, triangles_per_proc, quantities = \
-           pmesh_divide_metis(domain, numprocs)
 
-    # Build the mesh that should be assigned to each processor,
-    # this includes ghost nodes and the communicaiton pattern
-    print 'Build submeshes'    
-    submesh = build_submesh(nodes, triangles, boundary,\
-                            quantities, triangles_per_proc)
 
-    # Send the mesh partition to the appropriate processor
-    print 'Distribute submeshes'        
-    for p in range(1, numprocs):
-      send_submesh(submesh, triangles_per_proc, p)
+#---------------
+# Parallel stuff
+#---------------
 
-    # Build the local mesh for processor 0
-    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict = \
-              extract_hostmesh(submesh, triangles_per_proc)
+if myid == 0:
+    # Distribute the domain
+    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict,\
+            = distribute_mesh(domain)
 
+
+    domain_name = domain.get_name()
+    domain_dir = domain.get_datadir()
+
+    for p in range(pypar.size()):
+        pypar.send((domain_name, domain_dir), p) 
+    
     print 'Communication done'        
     
@@ -127,7 +117,11 @@
     # correct form for the GA data structure)
 
-    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict \
+    points, vertices, boundary, quantities, ghost_recv_dict, full_send_dict, \
             = rec_submesh(0)
 
+    print 'P %d receiving names' %myid
+    X = pypar.receive(0)
+    print X
+    (domain_name, domain_dir) = X
 
 
@@ -138,4 +132,5 @@
 
 
+
 # Build the domain for this processor
 domain = Parallel_Domain(points, vertices, boundary,
@@ -143,8 +138,8 @@
                          ghost_recv_dict = ghost_recv_dict)
 
-# Name etc currently has to be set here as they are not transferred from the
+# Name and dir, etc currently has to be set here as they are not transferred from the
 # original domain
-domain.set_name(project.basename)
-domain.set_datadir(project.outputdir)
+domain.set_name(domain_name)
+domain.set_datadir(domain_dir)
 
 
@@ -152,20 +147,11 @@
 # Setup initial conditions
 #------------------------------------------------------------------------------
+for q in quantities:
+    domain.set_quantity(q, quantities[q]) # Distribute elevation    
 
 
-domain.set_quantity('elevation', quantities['elevation']) # Distribute elevation 
-domain.set_quantity('stage', project.initial_sealevel)
-domain.set_quantity('friction', 0.03)
-
-#
-# FIXME (Ole): This one segfaults which is bad, because set_quantity is
-# time consuming and should be done here rather than on processor 0
-# It did not segfault today 2 Aug 2006 !!!
-# But values are zero ??....
-#
-#domain.set_quantity('elevation', 
-#                    filename=project.demname + '.pts',
-#                    use_cache=False,
-#                    verbose=True)
+#domain.set_quantity('elevation', quantities['elevation']) # Distribute elevation 
+#domain.set_quantity('stage', project.initial_sealevel)
+#domain.set_quantity('friction', 0.03)
 
 
Index: /anuga_work/production/wollongong_2006/run_flagstaff_sequential.py
===================================================================
--- /anuga_work/production/wollongong_2006/run_flagstaff_sequential.py	(revision 3584)
+++ /anuga_work/production/wollongong_2006/run_flagstaff_sequential.py	(revision 3585)
@@ -39,11 +39,5 @@
 
 
-#------------------------------------------------------------------------------
-# Preparation of topographic data
-#
-# Convert ASC 2 DEM 2 PTS using source data and store result in source data
-#------------------------------------------------------------------------------
 
-max_area = project.base_resolution
 
     
@@ -56,4 +50,5 @@
 
 print 'Generate mesh'
+max_area = project.base_resolution
 mesh = create_mesh_from_regions(project.bounding_polygon,
                                 boundary_tags=project.boundary_tags,
