| 1 | #ifdef IS_MPI | 
| 2 | #include <stdlib.h> | 
| 3 | #include <stdio.h> | 
| 4 | #include <string.h> | 
| 5 |  | 
| 6 | #define __mpiBASSEVENT | 
| 7 | #include "mpiBASS.h" | 
| 8 | #include "simError.h" | 
| 9 |  | 
| 10 |  | 
| 11 | void mpiCatchEvent(void); | 
| 12 |  | 
| 13 |  | 
| 14 |  | 
| 15 |  | 
| 16 | void mpiEventInit(void) | 
| 17 | { | 
| 18 | int blockCounts[5] = {1,3,4,120,80}; | 
| 19 | MPI_Aint dspls[5]; | 
| 20 | MPI_Datatype types[5]; | 
| 21 | mBEvent protoEvent; | 
| 22 |  | 
| 23 | int i; | 
| 24 |  | 
| 25 | MPI_Address(&protoEvent.type, &dspls[0]); | 
| 26 | MPI_Address(&protoEvent.d1, &dspls[1]); | 
| 27 | MPI_Address(&protoEvent.i1, &dspls[2]); | 
| 28 | MPI_Address(&protoEvent.cArray, &dspls[3]); | 
| 29 | MPI_Address(&protoEvent.lhs   , &dspls[4]); | 
| 30 |  | 
| 31 |  | 
| 32 | types[0] = MPI_INT; | 
| 33 | types[1] = MPI_DOUBLE; | 
| 34 | types[2] = MPI_INT; | 
| 35 | types[3] = MPI_CHAR; | 
| 36 | types[4] = MPI_CHAR; | 
| 37 |  | 
| 38 |  | 
| 39 | for (i =4; i >= 0; i--) dspls[i] -= dspls[0]; | 
| 40 |  | 
| 41 | MPI_Type_struct(5,blockCounts,dspls,types,&mpiBASSEventType); | 
| 42 | MPI_Type_commit(&mpiBASSEventType); | 
| 43 | } | 
| 44 |  | 
| 45 |  | 
| 46 | void throwMPIEvent(event* the_event) | 
| 47 | { | 
| 48 | mBEvent mpiEventContainer; | 
| 49 | int mpiStatus; | 
| 50 |  | 
| 51 |  | 
| 52 | if (the_event == NULL)     mpiStatus = MPI_INTERFACE_DONE; | 
| 53 | else                       mpiStatus = MPI_INTERFACE_CONTINUE; | 
| 54 |  | 
| 55 | MPI_Bcast(&mpiStatus,1,MPI_INT,0,MPI_COMM_WORLD); | 
| 56 |  | 
| 57 | if (!mpiStatus){ | 
| 58 | switch (the_event->event_type){ | 
| 59 | case MOLECULE: | 
| 60 | mpiEventContainer.type = mpiMOLECULE; | 
| 61 | mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int | 
| 62 | break; | 
| 63 |  | 
| 64 | case ATOM: | 
| 65 | mpiEventContainer.type = mpiATOM; | 
| 66 | mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int | 
| 67 | break; | 
| 68 |  | 
| 69 | case BOND: | 
| 70 | mpiEventContainer.type = mpiBOND; | 
| 71 | mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int | 
| 72 | break; | 
| 73 |  | 
| 74 | case BEND: | 
| 75 | mpiEventContainer.type = mpiBEND; | 
| 76 | mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int | 
| 77 | break; | 
| 78 |  | 
| 79 | case TORSION: | 
| 80 | mpiEventContainer.type = mpiTORSION; | 
| 81 | mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int | 
| 82 | break; | 
| 83 |  | 
| 84 | case COMPONENT: | 
| 85 | mpiEventContainer.type = mpiCOMPONENT; | 
| 86 | mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int | 
| 87 | break; | 
| 88 |  | 
| 89 | case POSITION: | 
| 90 | mpiEventContainer.type = mpiPOSITION; | 
| 91 | mpiEventContainer.d1 = the_event->evt.pos.x; // pack pos coord into d | 
| 92 | mpiEventContainer.d2 = the_event->evt.pos.y; | 
| 93 | mpiEventContainer.d3 = the_event->evt.pos.z; | 
| 94 | break; | 
| 95 |  | 
| 96 | case ORIENTATION: | 
| 97 | mpiEventContainer.type = mpiORIENTATION; | 
| 98 | mpiEventContainer.d1 = the_event->evt.ornt.x; // pack orientation coord into d | 
| 99 | mpiEventContainer.d2 = the_event->evt.ornt.y; | 
| 100 | mpiEventContainer.d3 = the_event->evt.ornt.z; | 
| 101 | break; | 
| 102 |  | 
| 103 | case CONSTRAINT: | 
| 104 | mpiEventContainer.type = mpiCONSTRAINT; | 
| 105 | mpiEventContainer.d1 = the_event->evt.cnstr; // pack constraint coord into d | 
| 106 | break; | 
| 107 |  | 
| 108 | case MEMBER: | 
| 109 | mpiEventContainer.type = mpiMEMBER; | 
| 110 | mpiEventContainer.i1 = the_event->evt.mbr.a ; // pack member ints into i | 
| 111 | mpiEventContainer.i2 = the_event->evt.mbr.b; | 
| 112 | mpiEventContainer.i3 = the_event->evt.mbr.c; | 
| 113 | mpiEventContainer.i4 = the_event->evt.mbr.d; | 
| 114 | break; | 
| 115 |  | 
| 116 | case ASSIGNMENT: | 
| 117 |  | 
| 118 | strcpy(mpiEventContainer.lhs,the_event->evt.asmt.lhs); | 
| 119 |  | 
| 120 | #ifdef MPIBASS_VERBOSE | 
| 121 |  | 
| 122 | fprintf(stderr, | 
| 123 | "mpiDiag at node %d: evt Assignment: \"%s\" = ?\n" | 
| 124 | "                    mpi Assignment: \"%s\" = ?\n", | 
| 125 | worldRank, | 
| 126 | the_event->evt.asmt.lhs, | 
| 127 | mpiEventContainer.lhs); | 
| 128 | #endif | 
| 129 |  | 
| 130 | switch (the_event->evt.asmt.asmt_type){ | 
| 131 | case STRING: | 
| 132 | mpiEventContainer.type = mpiASSIGNMENT_s; | 
| 133 | strcpy(mpiEventContainer.cArray,the_event->evt.asmt.rhs.sval); | 
| 134 | break; | 
| 135 |  | 
| 136 | case INT: | 
| 137 | mpiEventContainer.type = mpiASSIGNMENT_i; | 
| 138 | mpiEventContainer.i1 = the_event->evt.asmt.rhs.ival; | 
| 139 | break; | 
| 140 |  | 
| 141 | case DOUBLE: | 
| 142 | mpiEventContainer.type = mpiASSIGNMENT_d; | 
| 143 | mpiEventContainer.d1 = the_event->evt.asmt.rhs.dval; | 
| 144 | break; | 
| 145 | } | 
| 146 | break; | 
| 147 |  | 
| 148 | case BLOCK_END: | 
| 149 | mpiEventContainer.type = mpiBLOCK_END; | 
| 150 | break; | 
| 151 | } | 
| 152 |  | 
| 153 |  | 
| 154 | MPI_Bcast(&mpiEventContainer,1,mpiBASSEventType,0,MPI_COMM_WORLD); | 
| 155 |  | 
| 156 | sprintf( checkPointMsg, | 
| 157 | "BASS Event broadcast successful" ); | 
| 158 | MPIcheckPoint(); | 
| 159 | } | 
| 160 | } | 
| 161 |  | 
| 162 |  | 
| 163 | // Everybody but node 0 runs this | 
| 164 | void mpiEventLoop(void) | 
| 165 | { | 
| 166 | int mpiContinue; | 
| 167 |  | 
| 168 | #ifdef MPIBASS_VERBOSE | 
| 169 | fprintf(stderr, | 
| 170 | "event key List at node %d:\n" | 
| 171 | "  MOLECULE    %d\n" | 
| 172 | "  ATOM        %d\n" | 
| 173 | "  BOND        %d\n" | 
| 174 | "  BEND        %d\n" | 
| 175 | "  TORSION     %d\n" | 
| 176 | "  COMPONENT   %d\n" | 
| 177 | "  POSITION    %d\n" | 
| 178 | "  ASSIGNMENT  %d\n" | 
| 179 | "  MEMBER      %d\n" | 
| 180 | "  CONSTRAINT  %d\n" | 
| 181 | "  ORIENTATION %d\n" | 
| 182 | "  START_INDEX %d\n" | 
| 183 | "  BLOCK_END   %d\n" | 
| 184 | "\n", | 
| 185 | worldRank, | 
| 186 | MOLECULE, ATOM, BOND, BEND, TORSION, COMPONENT, | 
| 187 | POSITION, ASSIGNMENT, MEMBER, CONSTRAINT, ORIENTATION, | 
| 188 | START_INDEX, BLOCK_END ); | 
| 189 | #endif | 
| 190 |  | 
| 191 | MPI_Bcast(&mpiContinue,1,MPI_INT,0,MPI_COMM_WORLD); | 
| 192 |  | 
| 193 | while(!mpiContinue){ | 
| 194 |  | 
| 195 | mpiCatchEvent(); | 
| 196 |  | 
| 197 | MPI_Bcast(&mpiContinue,1,MPI_INT,0,MPI_COMM_WORLD); | 
| 198 | } | 
| 199 |  | 
| 200 | if (mpiContinue == MPI_INTERFACE_ABORT){ | 
| 201 | MPI_Finalize(); | 
| 202 | exit (0); | 
| 203 | } | 
| 204 | } | 
| 205 |  | 
| 206 | void mpiCatchEvent(void) | 
| 207 | { | 
| 208 | event the_event; | 
| 209 | mBEvent mpiEventContainer; | 
| 210 |  | 
| 211 |  | 
| 212 | MPI_Bcast(&mpiEventContainer,1,mpiBASSEventType,0,MPI_COMM_WORLD); | 
| 213 |  | 
| 214 | switch (mpiEventContainer.type){ | 
| 215 | case mpiMOLECULE: | 
| 216 | the_event.event_type = MOLECULE; | 
| 217 | the_event.evt.blk_index = mpiEventContainer.i1; | 
| 218 | break; | 
| 219 |  | 
| 220 | case mpiATOM: | 
| 221 | the_event.event_type = ATOM; | 
| 222 | the_event.evt.blk_index = mpiEventContainer.i1; | 
| 223 | break; | 
| 224 |  | 
| 225 | case mpiBOND: | 
| 226 | the_event.event_type = BOND; | 
| 227 | the_event.evt.blk_index = mpiEventContainer.i1; | 
| 228 | break; | 
| 229 |  | 
| 230 | case mpiBEND: | 
| 231 | the_event.event_type = BEND; | 
| 232 | the_event.evt.blk_index = mpiEventContainer.i1; | 
| 233 | break; | 
| 234 |  | 
| 235 | case mpiTORSION: | 
| 236 | the_event.event_type = TORSION; | 
| 237 | the_event.evt.blk_index = mpiEventContainer.i1; | 
| 238 | break; | 
| 239 |  | 
| 240 | case mpiCOMPONENT: | 
| 241 | the_event.event_type = COMPONENT; | 
| 242 | the_event.evt.blk_index = mpiEventContainer.i1; | 
| 243 | break; | 
| 244 |  | 
| 245 |  | 
| 246 | case mpiPOSITION: | 
| 247 | the_event.event_type = POSITION; | 
| 248 | the_event.evt.pos.x = mpiEventContainer.d1; | 
| 249 | the_event.evt.pos.y = mpiEventContainer.d2; | 
| 250 | the_event.evt.pos.z = mpiEventContainer.d3; | 
| 251 | break; | 
| 252 |  | 
| 253 | case mpiORIENTATION: | 
| 254 | the_event.event_type = ORIENTATION; | 
| 255 | the_event.evt.ornt.x = mpiEventContainer.d1; | 
| 256 | the_event.evt.ornt.y = mpiEventContainer.d2; | 
| 257 | the_event.evt.ornt.z = mpiEventContainer.d3; | 
| 258 | break; | 
| 259 |  | 
| 260 | case mpiCONSTRAINT: | 
| 261 | the_event.event_type = CONSTRAINT; | 
| 262 | the_event.evt.cnstr = mpiEventContainer.d1; | 
| 263 | break; | 
| 264 |  | 
| 265 | case mpiMEMBER: | 
| 266 | the_event.event_type = MEMBER; | 
| 267 | the_event.evt.mbr.a = mpiEventContainer.i1; | 
| 268 | the_event.evt.mbr.b = mpiEventContainer.i2; | 
| 269 | the_event.evt.mbr.c = mpiEventContainer.i3; | 
| 270 | the_event.evt.mbr.d = mpiEventContainer.i4; | 
| 271 | break; | 
| 272 |  | 
| 273 | case mpiASSIGNMENT_s: | 
| 274 | the_event.event_type = ASSIGNMENT; | 
| 275 | the_event.evt.asmt.asmt_type = STRING; | 
| 276 | strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs); | 
| 277 | strcpy(the_event.evt.asmt.rhs.sval,mpiEventContainer.cArray); | 
| 278 |  | 
| 279 | #ifdef MPIBASS_VERBOSE | 
| 280 |  | 
| 281 | fprintf(stderr, "mpiDiag at node %d: Assignment:  %s = %s\n", worldRank, | 
| 282 | the_event.evt.asmt.lhs, | 
| 283 | the_event.evt.asmt.rhs.sval ); | 
| 284 | #endif | 
| 285 |  | 
| 286 | break; | 
| 287 |  | 
| 288 | case mpiASSIGNMENT_i: | 
| 289 | the_event.event_type = ASSIGNMENT; | 
| 290 | the_event.evt.asmt.asmt_type = INT; | 
| 291 | strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs); | 
| 292 | the_event.evt.asmt.rhs.ival = mpiEventContainer.i1; | 
| 293 |  | 
| 294 | #ifdef MPIBASS_VERBOSE | 
| 295 |  | 
| 296 | fprintf(stderr, "mpiDiag at node %d: Assignment:  %s = %d\n", worldRank, | 
| 297 | the_event.evt.asmt.lhs, | 
| 298 | the_event.evt.asmt.rhs.ival ); | 
| 299 | #endif | 
| 300 |  | 
| 301 | break; | 
| 302 |  | 
| 303 | case mpiASSIGNMENT_d: | 
| 304 | the_event.event_type = ASSIGNMENT; | 
| 305 | the_event.evt.asmt.asmt_type = DOUBLE; | 
| 306 | strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs); | 
| 307 | the_event.evt.asmt.rhs.dval = mpiEventContainer.d1; | 
| 308 |  | 
| 309 | #ifdef MPIBASS_VERBOSE | 
| 310 |  | 
| 311 | fprintf(stderr, "mpiDiag at node %d: Assignment:  %s = %lf\n", worldRank, | 
| 312 | the_event.evt.asmt.lhs, | 
| 313 | the_event.evt.asmt.rhs.dval ); | 
| 314 | #endif | 
| 315 |  | 
| 316 | break; | 
| 317 |  | 
| 318 | case mpiBLOCK_END: | 
| 319 | the_event.event_type = BLOCK_END; | 
| 320 | break; | 
| 321 | } | 
| 322 |  | 
| 323 | #ifdef MPIBASS_VERBOSE | 
| 324 |  | 
| 325 | fprintf(stderr, "mpiDiag at node %d: event type is %d\n", worldRank, | 
| 326 | the_event.event_type); | 
| 327 | #endif | 
| 328 |  | 
| 329 | if (!event_handler(&the_event)){ | 
| 330 |  | 
| 331 | sprintf(painCave.errMsg, | 
| 332 | "MPI event handling error at node %d => %s\n", | 
| 333 | worldRank, | 
| 334 | the_event.err_msg); | 
| 335 | painCave.isFatal = 1; | 
| 336 | simError(); | 
| 337 | } | 
| 338 | MPIcheckPoint(); | 
| 339 | } | 
| 340 |  | 
| 341 |  | 
| 342 | void mpiInterfaceExit(void){ | 
| 343 | int mpiStatus = MPI_INTERFACE_ABORT; | 
| 344 |  | 
| 345 | MPI_Bcast(&mpiStatus,1,MPI_INT,0,MPI_COMM_WORLD); | 
| 346 | MPI_Finalize(); | 
| 347 | exit (0); | 
| 348 |  | 
| 349 | } | 
| 350 | #endif |