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