aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@aei.mpg.de>2004-12-30 19:10:00 +0000
committerErik Schnetter <schnetter@aei.mpg.de>2004-12-30 19:10:00 +0000
commitb261c5ff0e0730c9d5d04882865150f362986f35 (patch)
tree25aec406e442b068df2b9a4a33ea52d86557e860
parent411ebdcbdc1369d10e7929263dff0a3be93665a2 (diff)
CarpetLib: Change checking of processor number in data class
Remove functions gdata::lives_on_this_processor() and gdata::this_processor_is(proc). Introduce dist::rank() and dist::size() instead. Re-introduce assert statement in data::proc(). Move declaration and definition of assignment operator near the constructor and destructor. darcs-hash:20041230191026-891bb-90eeb1be4c04753c165e13e7c1e65f06847180ca.gz
-rw-r--r--Carpet/CarpetIOASCII/src/ioascii.cc1
-rw-r--r--Carpet/CarpetLib/src/data.cc32
-rw-r--r--Carpet/CarpetLib/src/dist.hh20
-rw-r--r--Carpet/CarpetLib/src/gdata.cc33
-rw-r--r--Carpet/CarpetLib/src/gdata.hh10
5 files changed, 50 insertions, 46 deletions
diff --git a/Carpet/CarpetIOASCII/src/ioascii.cc b/Carpet/CarpetIOASCII/src/ioascii.cc
index 505735e05..2b0cdb46f 100644
--- a/Carpet/CarpetIOASCII/src/ioascii.cc
+++ b/Carpet/CarpetIOASCII/src/ioascii.cc
@@ -1001,7 +1001,6 @@ namespace CarpetIOASCII {
const vect<CCTK_REAL,D>& coord_upper)
{
assert (DD<=D);
- assert (gfdata->has_storage());
if (gfdata->proc()==0) {
// output on processor 0
diff --git a/Carpet/CarpetLib/src/data.cc b/Carpet/CarpetLib/src/data.cc
index c8de2fa5d..2d4192e13 100644
--- a/Carpet/CarpetLib/src/data.cc
+++ b/Carpet/CarpetLib/src/data.cc
@@ -177,7 +177,7 @@ void data<T,D>::allocate (const ibbox& extent_,
this->_size *= this->_shape[d];
}
this->_proc = proc_;
- if (this->lives_on_this_processor()) {
+ if (dist::rank() == this->_proc) {
this->_owns_storage = !mem;
if (this->_owns_storage) {
if (this->vectorindex == 0) {
@@ -239,7 +239,7 @@ void data<T,D>::change_processor_recv (comm_state<D>& state,
assert (!this->comm_active);
this->comm_active = true;
- if (newproc == this->proc()) {
+ if (newproc == this->_proc) {
assert (!mem);
return;
}
@@ -247,7 +247,7 @@ void data<T,D>::change_processor_recv (comm_state<D>& state,
wtime_changeproc_recv.start();
if (this->_has_storage) {
- if (this->this_processor_is ( newproc)) {
+ if (dist::rank() == newproc) {
// copy from other processor
assert (!_storage);
@@ -268,7 +268,7 @@ void data<T,D>::change_processor_recv (comm_state<D>& state,
state.requests.push_back (this->request);
}
- } else if (this->lives_on_this_processor()) {
+ } else if (dist::rank() == this->_proc) {
// copy to other processor
} else {
@@ -291,7 +291,7 @@ void data<T,D>::change_processor_send (comm_state<D>& state,
assert (this->comm_active);
- if (newproc == this->proc()) {
+ if (newproc == this->_proc) {
assert (!mem);
return;
}
@@ -299,10 +299,10 @@ void data<T,D>::change_processor_send (comm_state<D>& state,
wtime_changeproc_send.start();
if (this->_has_storage) {
- if (this->this_processor_is ( newproc)) {
+ if (dist::rank() == newproc) {
// copy from other processor
- } else if (this->lives_on_this_processor()) {
+ } else if (dist::rank() == this->_proc) {
// copy to other processor
assert (!mem);
@@ -338,7 +338,7 @@ void data<T,D>::change_processor_wait (comm_state<D>& state,
assert (this->comm_active);
this->comm_active = false;
- if (newproc == this->proc()) {
+ if (newproc == this->_proc) {
assert (!mem);
return;
}
@@ -357,7 +357,7 @@ void data<T,D>::change_processor_wait (comm_state<D>& state,
}
if (this->_has_storage) {
- if (this->this_processor_is ( newproc )) {
+ if (dist::rank() == newproc) {
// copy from other processor
if (! use_waitall) {
@@ -367,7 +367,7 @@ void data<T,D>::change_processor_wait (comm_state<D>& state,
wtime_irecvwait.stop();
}
- } else if (this->lives_on_this_processor()) {
+ } else if (dist::rank() == this->_proc) {
// copy to other processor
assert (!mem);
@@ -426,7 +426,7 @@ void data<T,D>
"There is no copy operator available for the variable type %s, dimension %d.",
typestring(Tdummy), D);
- assert (this->lives_on_this_processor());
+ assert (dist::rank() == this->proc());
for (typename ibbox::iterator it=box.begin(); it!=box.end(); ++it) {
const ivect index = *it;
@@ -462,7 +462,7 @@ void data<T,D>
assert (order_space >= 0);
assert (order_time >= 0);
- assert (this->lives_on_this_processor());
+ assert (dist::rank() == this->proc());
assert (this->varindex >= 0);
const int groupindex = CCTK_GroupIndexFromVarI (this->varindex);
@@ -547,7 +547,7 @@ void data<CCTK_INT4,3>
assert (proc() == src->proc());
- assert (lives_on_this_processor());
+ assert (dist::rank() == proc());
const ibbox& sext = src->extent();
const ibbox& dext = extent();
@@ -590,7 +590,7 @@ void data<CCTK_REAL8,3>
assert (proc() == src->proc());
- assert (lives_on_this_processor());
+ assert (dist::rank() == proc());
const ibbox& sext = src->extent();
const ibbox& dext = extent();
@@ -633,7 +633,7 @@ void data<CCTK_COMPLEX16,3>
assert (proc() == src->proc());
- assert (lives_on_this_processor());
+ assert (dist::rank() == proc());
const ibbox& sext = src->extent();
const ibbox& dext = extent();
@@ -1356,7 +1356,7 @@ void data<CCTK_REAL8,3>
assert (proc() == srcs[0]->proc());
- assert (lives_on_this_processor());
+ assert (dist::rank() == proc());
Check_that_the_times_are_consistent (times, time);
diff --git a/Carpet/CarpetLib/src/dist.hh b/Carpet/CarpetLib/src/dist.hh
index fccf76179..3216b49b5 100644
--- a/Carpet/CarpetLib/src/dist.hh
+++ b/Carpet/CarpetLib/src/dist.hh
@@ -43,6 +43,26 @@ namespace dist {
+ // Information about the communicator
+
+ // Rank in the communicator (this processor's number, 0 .. size-1)
+ inline int rank ()
+ {
+ int rank_;
+ MPI_Comm_rank (comm, &rank_);
+ return rank_;
+ }
+
+ // Size of the communicator
+ inline int size ()
+ {
+ int size_;
+ MPI_Comm_size (comm, &size_);
+ return size_;
+ }
+
+
+
// Datatype helpers
inline MPI_Datatype datatype (const char& dummy)
{ return MPI_CHAR; }
diff --git a/Carpet/CarpetLib/src/gdata.cc b/Carpet/CarpetLib/src/gdata.cc
index fa7324a51..507ea0b44 100644
--- a/Carpet/CarpetLib/src/gdata.cc
+++ b/Carpet/CarpetLib/src/gdata.cc
@@ -229,6 +229,13 @@ gdata<D>::~gdata ()
}
}
+// Assignment
+template<int D>
+gdata<D> & gdata<D>::operator= (gdata const & from)
+{
+ return * this = from;
+}
+
// Processor management
@@ -317,7 +324,7 @@ void gdata<D>::copy_from_nocomm (const gdata* src, const ibbox& box)
assert (proc() == src->proc());
// copy on same processor
- if (lives_on_this_processor()) {
+ if (dist::rank() == proc()) {
copy_from_innerloop (src, box);
}
}
@@ -524,7 +531,7 @@ void gdata<D>
assert (transport_operator != op_none);
// interpolate on same processor
- if (lives_on_this_processor()) {
+ if (dist::rank() == proc()) {
interpolate_from_innerloop
(srcs, times, box, time, order_space, order_time);
}
@@ -657,28 +664,6 @@ void gdata<D>
}
-template<int D>
-bool gdata<D>
-::this_processor_is (int procno)
-{
- int rank;
- MPI_Comm_rank (dist::comm, &rank);
- return rank == procno;
-}
-
-template<int D>
-bool gdata<D>
-::lives_on_this_processor ()
-{
- return this_processor_is( proc() );
-}
-
-template<int D>
-gdata<D>& gdata<D>
-::operator = ( const gdata & ) // canonical copy
-{
- return *this; // does nothing
-}
template class comm_state<3>;
template class gdata<3>;
diff --git a/Carpet/CarpetLib/src/gdata.hh b/Carpet/CarpetLib/src/gdata.hh
index 30615eab9..9d544f9bb 100644
--- a/Carpet/CarpetLib/src/gdata.hh
+++ b/Carpet/CarpetLib/src/gdata.hh
@@ -102,7 +102,7 @@ class gdata {
protected: // should be readonly
// Fields
- const int varindex; // Cactus variable index, or -1
+ const int varindex; // Cactus variable index, or -1
operator_type transport_operator;
bool _has_storage; // has storage associated (on some processor)
@@ -136,6 +136,9 @@ public:
make_typed (const int varindex,
const operator_type transport_operator = op_error) const = 0;
+ // Assignment
+ gdata & operator= (gdata const & from);
+
// Processor management
void change_processor (comm_state<D>& state,
const int newproc,
@@ -182,6 +185,7 @@ public:
}
int proc () const {
+ assert (_has_storage);
return _proc;
}
@@ -255,9 +259,6 @@ public:
public:
protected:
- bool this_processor_is (int procno);
- bool lives_on_this_processor ();
-
virtual void
copy_from_innerloop (const gdata* src, const ibbox& box) = 0;
virtual void
@@ -266,7 +267,6 @@ protected:
const ibbox& box, const CCTK_REAL time,
const int order_space,
const int order_time) = 0;
- gdata & operator =( const gdata & ); // canonical copy
};