00001
00002
00004 #ifndef EVENTID_H
00005 #define EVENTID_H
00006 #include "charm++.h"
00007 #include "limits.h"
00008
00009 #ifdef _WIN32
00010 #define snprintf _snprintf
00011 #endif
00012
00014 class eventID
00015 {
00017 int pe;
00019 int control;
00020 public:
00022 unsigned int id;
00024 eventID() : pe(CkMyPe()), control (0), id(0) { }
00025
00027 inline void init() { id = 0; pe = -1; control = INT_MIN; }
00029
00030 inline void incEventID() {
00031 id++;
00032 if (id == 0) CkPrintf("WARNING: event ID rollover occurred!\n");
00033 }
00035 inline eventID& operator=(const eventID& e) {
00036 CmiAssert((e.pe >= 0) || (e.pe < CkNumPes()));
00037 id = e.id; pe = e.pe; control = e.control; return *this;
00038 }
00040 inline int getPE() { return pe; }
00042 inline int getControl() { return control; }
00044 inline void setControl(int ctrl) { control = ctrl; }
00046 inline int operator==(const eventID& o) {
00047 return ((id == o.id) && (pe == o.pe) && (control == o.control));
00048 }
00050
00051 inline int operator<=(const eventID& o) {
00052 return (control <= o.control);
00053 }
00055
00056 inline int operator<(const eventID& o) {
00057 return (control < o.control);
00058 }
00060
00061 inline int operator>=(const eventID& o) {
00062 return (control >= o.control);
00063 }
00065
00066 inline int operator> (const eventID& o) {
00067 return (control > o.control);
00068 }
00069
00071 inline void dump() {
00072 CmiAssert((pe >= 0) && (pe < CkNumPes()));
00073 CkPrintf("%d.%d", id, pe);
00074 }
00075 inline char *sdump(char *s) { sprintf(s, "%d.%d", id, pe); return s;}
00076 inline char *sndump(char *s,size_t n) { snprintf(s,n,"%d.%d", id, pe); return s;}
00078 inline void pup(class PUP::er &p) { p(id); p(pe); }
00079 inline void sanitize() { CkAssert((pe > -1) && (pe < CkNumPes())); }
00080 };
00081
00083 const eventID& GetEventID();
00084
00085 #endif