[cig-commits] r4033 - in cs/pythia/trunk: journal mpi
leif at geodynamics.org
leif at geodynamics.org
Tue Jul 18 23:59:26 PDT 2006
Author: leif
Date: 2006-07-18 23:59:26 -0700 (Tue, 18 Jul 2006)
New Revision: 4033
Modified:
cs/pythia/trunk/journal/Diagnostic.h
cs/pythia/trunk/journal/NullDiagnostic.h
cs/pythia/trunk/journal/SeverityDebug.h
cs/pythia/trunk/journal/SeverityError.h
cs/pythia/trunk/journal/SeverityFirewall.h
cs/pythia/trunk/journal/SeverityInfo.h
cs/pythia/trunk/journal/SeverityWarning.h
cs/pythia/trunk/mpi/Communicator.h
cs/pythia/trunk/mpi/Group.h
Log:
Inlined mpimodule's C++ implementation. Inlined
or temporarily stubbed-out libjournal's implementation.
Modified: cs/pythia/trunk/journal/Diagnostic.h
===================================================================
--- cs/pythia/trunk/journal/Diagnostic.h 2006-07-19 04:26:06 UTC (rev 4032)
+++ cs/pythia/trunk/journal/Diagnostic.h 2006-07-19 06:59:26 UTC (rev 4033)
@@ -29,7 +29,7 @@
// types
public:
typedef Entry entry_t;
- typedef Facility state_t;
+ typedef bool state_t;
typedef Journal journal_t;
typedef std::string string_t;
@@ -37,8 +37,9 @@
// interface
public:
- void state(bool);
- bool state() const;
+ void state(bool flag) { _state = flag; }
+ bool state() const { return _state; }
+ static state_t & lookup(string_t name) { static state_t dummy; return dummy; }
void activate() { state(true); }
void deactivate() { state(false); }
@@ -46,9 +47,11 @@
string_t facility() const { return _facility; }
// entry manipulation
- void record();
- void newline();
- void attribute(string_t, string_t);
+ void record() { /**/ }
+ void newline() { if (state()) _newline(); }
+ void attribute(string_t key, string_t value) {
+ /*(*_entry)[key] = value;*/
+ }
// access to the buffered data
string_t str() const { return _buffer.str(); }
@@ -58,19 +61,24 @@
// builtin data type injection
template <typename item_t>
- Diagnostic & inject(item_t datum) {
+ Diagnostic & inject(item_t item) {
_buffer << item;
return *this;
}
// meta-methods
public:
- ~Diagnostic();
- Diagnostic(string_t, string_t, state_t &);
+ ~Diagnostic() { /*delete _entry;*/ }
+ Diagnostic(string_t facility, string_t severity, state_t & state):
+ _facility(facility), _severity(severity),
+ _state(state), _buffer(), _entry(0 /*new entry_t*/) {}
// implementation
private:
- void _newline();
+ void _newline() {
+ /*_entry->newline(str());*/
+ _buffer.str(string_t());
+ }
// disable these
private:
Modified: cs/pythia/trunk/journal/NullDiagnostic.h
===================================================================
--- cs/pythia/trunk/journal/NullDiagnostic.h 2006-07-19 04:26:06 UTC (rev 4032)
+++ cs/pythia/trunk/journal/NullDiagnostic.h 2006-07-19 06:59:26 UTC (rev 4033)
@@ -48,11 +48,11 @@
// manipulators
namespace journal {
- const NullDiagnostic & endl(const NullDiagnostic &) {
+ const NullDiagnostic & endl(const NullDiagnostic & diagnostic) {
return diagnostic;
}
- const NullDiagnostic & newline(const NullDiagnostic &) {
+ const NullDiagnostic & newline(const NullDiagnostic & diagnostic) {
return diagnostic;
}
Modified: cs/pythia/trunk/journal/SeverityDebug.h
===================================================================
--- cs/pythia/trunk/journal/SeverityDebug.h 2006-07-19 04:26:06 UTC (rev 4032)
+++ cs/pythia/trunk/journal/SeverityDebug.h 2006-07-19 06:59:26 UTC (rev 4033)
@@ -19,24 +19,18 @@
namespace journal {
class Diagnostic;
class SeverityDebug;
- class Index;
}
class journal::SeverityDebug : public journal::Diagnostic {
-// types
-public:
- typedef Index index_t;
-
// interface
public:
string_t name() const { return "debug." + facility(); }
- static state_t & lookup(string_t);
// meta-methods
public:
- virtual ~SeverityDebug();
+ ~SeverityDebug() {}
SeverityDebug(string_t name) :
Diagnostic(name, "debug", lookup(name)) {}
@@ -45,10 +39,6 @@
private:
SeverityDebug(const SeverityDebug &);
const SeverityDebug & operator=(const SeverityDebug &);
-
-// data
-private:
- static index_t * _index;
};
Modified: cs/pythia/trunk/journal/SeverityError.h
===================================================================
--- cs/pythia/trunk/journal/SeverityError.h 2006-07-19 04:26:06 UTC (rev 4032)
+++ cs/pythia/trunk/journal/SeverityError.h 2006-07-19 06:59:26 UTC (rev 4033)
@@ -19,24 +19,18 @@
namespace journal {
class Diagnostic;
class SeverityError;
- class Index;
}
class journal::SeverityError : public journal::Diagnostic {
-// types
-public:
- typedef Index index_t;
-
// interface
public:
string_t name() const { return "error." + facility(); }
- static state_t & lookup(string_t);
// meta-methods
public:
- virtual ~SeverityError();
+ ~SeverityError() {}
SeverityError(string_t name) :
Diagnostic(name, "error", lookup(name)) {}
@@ -45,10 +39,6 @@
private:
SeverityError(const SeverityError &);
const SeverityError & operator=(const SeverityError &);
-
-// data
-private:
- static index_t * _index;
};
Modified: cs/pythia/trunk/journal/SeverityFirewall.h
===================================================================
--- cs/pythia/trunk/journal/SeverityFirewall.h 2006-07-19 04:26:06 UTC (rev 4032)
+++ cs/pythia/trunk/journal/SeverityFirewall.h 2006-07-19 06:59:26 UTC (rev 4033)
@@ -19,24 +19,18 @@
namespace journal {
class Diagnostic;
class SeverityFirewall;
- class Index;
}
class journal::SeverityFirewall : public journal::Diagnostic {
-// types
-public:
- typedef Index index_t;
-
// interface
public:
string_t name() const { return "firewall." + facility(); }
- static state_t & lookup(string_t);
// meta-methods
public:
- virtual ~SeverityFirewall();
+ ~SeverityFirewall() {}
SeverityFirewall(string_t name) :
Diagnostic(name, "firewall", lookup(name)) {}
@@ -45,10 +39,6 @@
private:
SeverityFirewall(const SeverityFirewall &);
const SeverityFirewall & operator=(const SeverityFirewall &);
-
-// data
-private:
- static index_t * _index;
};
Modified: cs/pythia/trunk/journal/SeverityInfo.h
===================================================================
--- cs/pythia/trunk/journal/SeverityInfo.h 2006-07-19 04:26:06 UTC (rev 4032)
+++ cs/pythia/trunk/journal/SeverityInfo.h 2006-07-19 06:59:26 UTC (rev 4033)
@@ -19,24 +19,18 @@
namespace journal {
class Diagnostic;
class SeverityInfo;
- class Index;
}
class journal::SeverityInfo : public journal::Diagnostic {
-// types
-public:
- typedef Index index_t;
-
// interface
public:
string_t name() const { return "info." + facility(); }
- static state_t & lookup(string_t);
// meta-methods
public:
- virtual ~SeverityInfo();
+ ~SeverityInfo() {}
SeverityInfo(string_t name) :
Diagnostic(name, "info", lookup(name)) {}
@@ -45,10 +39,6 @@
private:
SeverityInfo(const SeverityInfo &);
const SeverityInfo & operator=(const SeverityInfo &);
-
-// data
-private:
- static index_t * _index;
};
Modified: cs/pythia/trunk/journal/SeverityWarning.h
===================================================================
--- cs/pythia/trunk/journal/SeverityWarning.h 2006-07-19 04:26:06 UTC (rev 4032)
+++ cs/pythia/trunk/journal/SeverityWarning.h 2006-07-19 06:59:26 UTC (rev 4033)
@@ -19,24 +19,18 @@
namespace journal {
class Diagnostic;
class SeverityWarning;
- class Index;
}
class journal::SeverityWarning : public journal::Diagnostic {
-// types
-public:
- typedef Index index_t;
-
// interface
public:
string_t name() const { return "warning." + facility(); }
- static state_t & lookup(string_t);
// meta-methods
public:
- virtual ~SeverityWarning();
+ ~SeverityWarning() {}
SeverityWarning(string_t name) :
Diagnostic(name, "warning", lookup(name)) {}
@@ -45,10 +39,6 @@
private:
SeverityWarning(const SeverityWarning &);
const SeverityWarning & operator=(const SeverityWarning &);
-
-// data
-private:
- static index_t * _index;
};
Modified: cs/pythia/trunk/mpi/Communicator.h
===================================================================
--- cs/pythia/trunk/mpi/Communicator.h 2006-07-19 04:26:06 UTC (rev 4032)
+++ cs/pythia/trunk/mpi/Communicator.h 2006-07-19 06:59:26 UTC (rev 4033)
@@ -14,6 +14,8 @@
#if !defined(pympi_Communicator_h__)
#define pympi_Communicator_h__
+#include <mpi.h>
+
namespace mpi {
class Group;
@@ -23,23 +25,44 @@
class mpi::Communicator {
// interface
public:
- int size() const;
- int rank() const;
+
+ int size() const {
+ int size;
+ return (MPI_Comm_size(_communicator, &size) == MPI_SUCCESS) ? size : -1;
+ }
+
+ int rank() const {
+ int rank;
+ return (MPI_Comm_rank(_communicator, &rank) == MPI_SUCCESS) ? rank : -1;
+ }
- void barrier() const;
- void cartesianCoordinates(int rank, int dim, int * coordinates) const;
+ void barrier() const { MPI_Barrier(_communicator); }
+
+ void cartesianCoordinates(int rank, int dim, int * coordinates) const {
+ MPI_Cart_coords(_communicator, rank, dim, coordinates);
+ }
- MPI_Comm handle() const;
+ MPI_Comm handle() const { return _communicator; }
// factories
- Communicator * communicator(const Group & group) const;
- Communicator * cartesian(int size, int * procs, int * periods, int reorder) const;
+ inline Communicator * communicator(const Group & group) const;
+
+ Communicator * cartesian(int size, int * procs, int * periods, int reorder) const {
+ MPI_Comm cartesian;
+ int status = MPI_Cart_create(_communicator, size, procs, periods, reorder, &cartesian);
+ if (status != MPI_SUCCESS || cartesian == MPI_COMM_NULL) {
+ return 0;
+ }
+ return new Communicator(cartesian);
+ }
// meta-methods
public:
- Communicator(MPI_Comm handle);
- virtual ~Communicator();
+ Communicator(MPI_Comm handle) :
+ _communicator(handle) {}
+
+ ~Communicator() { MPI_Comm_free(&_communicator); }
// hide these
private:
@@ -52,8 +75,26 @@
MPI_Comm _communicator;
};
+
+#if !defined(pympi_Group_h__)
+#include "Group.h"
#endif
+
+mpi::Communicator * mpi::Communicator::communicator(const Group & group) const {
+ MPI_Comm oldHandle = _communicator;
+ MPI_Group groupHandle = group.handle();
+ MPI_Comm comm;
+ int status = MPI_Comm_create(oldHandle, groupHandle, &comm);
+ if (status != MPI_SUCCESS || comm == MPI_COMM_NULL) {
+ return 0;
+ }
+ return new Communicator(comm);
+}
+
+
+#endif
+
// version
// $Id: Communicator.h,v 1.1.1.1 2005/03/08 16:13:30 aivazis Exp $
Modified: cs/pythia/trunk/mpi/Group.h
===================================================================
--- cs/pythia/trunk/mpi/Group.h 2006-07-19 04:26:06 UTC (rev 4032)
+++ cs/pythia/trunk/mpi/Group.h 2006-07-19 06:59:26 UTC (rev 4033)
@@ -14,6 +14,8 @@
#if !defined(pympi_Group_h__)
#define pympi_Group_h__
+#include <mpi.h>
+
namespace mpi {
class Group;
@@ -25,20 +27,44 @@
// interface
public:
- int size() const;
- int rank() const;
- MPI_Group handle() const;
+
+ int size() const {
+ int size;
+ return (MPI_Group_size(_group, &size) == MPI_SUCCESS) ? size : -1;
+ }
+
+ int rank() const {
+ int rank;
+ return (MPI_Group_rank(_group, &rank) == MPI_SUCCESS) ? rank : -1;
+ }
+
+ MPI_Group handle() const { return _group; }
// factories
- static Group * group(const Communicator & comm);
+ static inline Group * group(const Communicator & comm);
- Group * include(int size, int ranks[]) const;
- Group * exclude(int size, int ranks[]) const;
+ Group * include(int size, int ranks[]) const {
+ MPI_Group newGroup = MPI_GROUP_NULL;
+ int status = MPI_Group_incl(_group, size, ranks, &newGroup);
+ if (status != MPI_SUCCESS || newGroup == MPI_GROUP_NULL) {
+ return 0;
+ }
+ return new Group(newGroup);
+ }
+ Group * exclude(int size, int ranks[]) const {
+ MPI_Group newGroup = MPI_GROUP_NULL;
+ int status = MPI_Group_excl(_group, size, ranks, &newGroup);
+ if (status != MPI_SUCCESS || newGroup == MPI_GROUP_NULL) {
+ return 0;
+ }
+ return new Group(newGroup);
+ }
+
// meta-methods
public:
- Group(MPI_Group handle);
- virtual ~Group();
+ Group(MPI_Group handle) : _group(handle) {}
+ ~Group() { MPI_Group_free(&_group); }
// hide these
private:
@@ -52,6 +78,23 @@
MPI_Group _group;
};
+
+#if !defined(pympi_Communicator_h__)
+#include "Communicator.h"
+#endif
+
+
+mpi::Group * mpi::Group::group(const mpi::Communicator & comm) {
+ MPI_Comm commHandle = comm.handle();
+ MPI_Group group;
+ int status = MPI_Comm_group(commHandle, &group);
+ if (status != MPI_SUCCESS || group == MPI_GROUP_NULL) {
+ return 0;
+ }
+ return new Group(group);
+}
+
+
// version
// $Id: Group.h,v 1.1.1.1 2005/03/08 16:13:30 aivazis Exp $
More information about the cig-commits
mailing list