/[escript]/branches/split/escriptcore/src/WorldSplitter.cpp
ViewVC logotype

Contents of /branches/split/escriptcore/src/WorldSplitter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4730 - (show annotations)
Mon Mar 10 00:24:45 2014 UTC (4 years, 11 months ago) by jfenwick
File size: 3534 byte(s)
Some missing files
1 /*****************************************************************************
2 *
3 * Copyright (c) 2014 by University of Queensland
4 * http://www.uq.edu.au
5 *
6 * Primary Business: Queensland, Australia
7 * Licensed under the Open Software License version 3.0
8 * http://www.opensource.org/licenses/osl-3.0.php
9 *
10 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 * Development 2012-2013 by School of Earth Sciences
12 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 *
14 *****************************************************************************/
15
16 #include "esysUtils/Esys_MPI.h"
17 #include "WorldSplitter.h"
18 #include "AbstractDomain.h"
19 #include "DomainException.h"
20
21 using namespace boost::python;
22 using namespace escript;
23
24 WorldSplitter::WorldSplitter(unsigned int numgroups, MPI_Comm global)
25 :globalcom(global), subcom(MPI_COMM_NULL), localworld((SubWorld*)0), groupcount(numgroups)
26 {
27 int gsize;
28 int grank;
29 if ((MPI_Comm_size(global, &gsize)!=MPI_SUCCESS) || (MPI_Comm_size(global, &grank)!=MPI_SUCCESS))
30 {
31 throw DomainException("MPI appears to be inoperative.");
32 }
33 if (gsize%numgroups!=0)
34 {
35 throw DomainException("WorldSplitter error: requested number of groups is not a factor of global communicator size.");
36 }
37 int res=MPI_Comm_split(MPI_COMM_WORLD, grank/gsize, grank%gsize, &subcom);
38 if (res!=MPI_SUCCESS)
39 {
40 throw DomainException("WorldSplitter error: Unable to form communicator.");
41 }
42 std::cerr << subcom << std::endl;
43 localworld=SubWorld_ptr(new SubWorld(subcom));
44 }
45
46 // We may need to look into this more closely.
47 // What if the domain lives longer than the world splitter?
48 WorldSplitter::~WorldSplitter()
49 {
50 if (subcom!=MPI_COMM_NULL)
51 {
52 MPI_Comm_free(&subcom);
53 }
54 }
55
56
57 // The boost wrapper will ensure that there is at least one entry in the tuple
58 object WorldSplitter::buildDomains(tuple t, dict kwargs)
59 {
60 int tsize=len(t);
61 // get the callable that we will invoke in a sec
62 object tocall=t[0];
63 // make a new tuple without the first element
64 tuple ntup=tuple(t.slice(1,tsize));
65 // now add the subworld to the kwargs
66 kwargs["escriptworld"]=localworld;
67
68 // std::cerr << "About to call function with:\n";
69 // //extract<std::string> ex(ntup.attr("__str__")());
70 // std::cerr << extract<std::string>(ntup.attr("__str__")())() << std::endl;
71 // // for (int i=0;i<tsize-1;++i)
72 // // {
73 // // std::cout << extract<const char*>(ntup[i])() << " ";
74 // // }
75 // std::cerr << std::endl;
76
77 // pass the whole package to the python call
78 object dobj=tocall(*ntup, **kwargs);
79 extract<Domain_ptr> ex1(dobj);
80 Domain_ptr dptr=ex1();
81
82 // now do a sanity check to see if the domain has respected the communicator info we passed it.
83 if (dptr->getMPIComm()!=localworld->getComm())
84 {
85 throw DomainException("The newly constructed domain is not using the correct communicator.");
86 }
87 localworld->setDomain(dptr);
88 return object(); // return None
89 }
90
91 namespace escript
92 {
93
94 boost::python::object raw_buildDomains(boost::python::tuple t, boost::python::dict kwargs)
95 {
96 int l=len(t);
97 if (l<2)
98 {
99 throw DomainException("Insufficient parameters to buildDomains.");
100 }
101 extract<WorldSplitter&> exw(t[0]);
102 if (!exw.check())
103 {
104 throw DomainException("First parameter to buildDomains must be a WorldSplitter.");
105 }
106 WorldSplitter& ws=exw();
107 tuple ntup=tuple(t.slice(1,l)); // strip off the object param
108 return ws.buildDomains(ntup, kwargs);
109 }
110
111 }

  ViewVC Help
Powered by ViewVC 1.1.26