Actual source code: Coaster.cxx
1: #define ALE_Coaster_cxx
3: #include <Coaster.hh>
5: namespace ALE {
7: #undef __FUNCT__
9: Coaster::Coaster(const Coaster &c) {
10: this->comm = c.comm;
11: this->commRank = c.commRank;
12: this->commSize = c.commSize;
13: this->verbosity = c.verbosity;
14: this->_lock = 0;
15: this->petscObj = c.petscObj;
16: if(this->petscObj != NULL) {
18: PetscObjectReference(this->petscObj); CHKERROR(ierr, "Failed on PetscObjectReference");
19: }
20: }// Coaster::Coaster()
23: #undef __FUNCT__
25: void Coaster::setComm(MPI_Comm c) {
26: if (this->comm == c) {
27: return;
28: }
29: if ((this->comm != MPI_COMM_NULL) && (this->comm != c)) {
30: throw ALE::Exception("Cannot reset the communicator");
31: }
33: this->comm = c;
34: MPI_Comm_rank(this->comm, &this->commRank); CHKERROR(ierr, "Error in MPI_Comm_rank");
35: MPI_Comm_size(this->comm, &this->commSize); CHKERROR(ierr, "Error in MPI_Comm_rank");
36: PetscObjectCreate(this->comm, &this->petscObj); CHKERROR(ierr, "Failed on PetscObjectCreate");
37: }// Coaster::setComm()
38:
39: #undef __FUNCT__
41: Coaster& Coaster::clear(){
42: this->comm = MPI_COMM_NULL;
43: this->commRank = -1;
44: this->commSize = 0;
45: if(this->petscObj != NULL) {
47: PetscObjectDestroy(this->petscObj); CHKERROR(ierr, "Error in PetscObjectDestroy");
48: }
49: this->petscObj = NULL;
50: this->verbosity = 0;
51: this->_lock = 0;
52: return *this;
53: }// Coaster::clear()
55: #undef __FUNCT__
57: Coaster& Coaster::getLock(){
58: CHKCOMM(*this);
59: this->_lock++;
60: PetscErrorCode MPI_Barrier(this->getComm()); CHKERROR(ierr, "Error in MPI_Barrier");
61: return *this;
62: }//Coaster::getLock()
63:
64: #undef __FUNCT__
66: Coaster& Coaster::releaseLock(){
67: CHKCOMM(*this);
68: if(this->_lock == 0){
69: throw ALE::Exception("Cannot release non-existent lock");
70: }
71: PetscErrorCode MPI_Barrier(this->getComm()); CHKERROR(ierr, "Error in MPI_Barrier");
72: this->_lock--;
73: return *this;
74: }//Coaster::releaseLock()
76: #undef __FUNCT__
78: void Coaster::assertLock(bool status){
79: if(status != this->isLocked()) {
80: throw Exception("Lock status assertion failed");
81: }
82: }// Coaster::assertLock()
85: #undef __FUNCT__
87: void Coaster::view(const char *name){}
90: // A helper friend function that checks whether the communicator is set on an ALE::Coaster object,
91: // and throws an exception otherwise.
92: void CHKCOMM(Coaster& obj) {
93: if(obj.comm == MPI_COMM_NULL){
94: throw ALE::Exception("ALE: Communicator not set");
95: }
96: }// CHKCOMM()
98: // A helper friend function that checks whether the communicators are set on a pair of ALE::Coaster objects,
99: // that the communicators are the same, and throws an exception otherwise.
100: void CHKCOMMS(Coaster& obj1, Coaster& obj2) {
101: if((obj1.comm == MPI_COMM_NULL) || (obj2.comm == MPI_COMM_NULL)){
102: throw ALE::Exception("ALE: Communicator not set");
103: }
104: int result;
105: MPI_Comm_compare(obj1.comm, obj2.comm, &result);
106: if(result == MPI_UNEQUAL) {
107: throw ALE::Exception("ALE: Incompatible communicators");
108: }
109: }// CHKCOMMS()
111: }
113: #undef ALE_Coaster_cxx