| 35 | 
  | 
 *                                                                       | 
| 36 | 
  | 
 * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).              | 
| 37 | 
  | 
 * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).           | 
| 38 | 
< | 
 * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).           | 
| 39 | 
< | 
 * [4]  Vardeman & Gezelter, in progress (2009).                         | 
| 38 | 
> | 
 * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).           | 
| 39 | 
> | 
 * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | 
> | 
 * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | 
  | 
 */ | 
| 42 | 
+ | 
#ifdef  IS_MPI | 
| 43 | 
+ | 
#include <mpi.h> | 
| 44 | 
+ | 
#endif | 
| 45 | 
  | 
  | 
| 46 | 
  | 
#include <stdlib.h> | 
| 47 | 
  | 
#include <stdio.h> | 
| 48 | 
  | 
#include <string.h> | 
| 49 | 
  | 
#include "config.h" | 
| 46 | 
– | 
#ifdef  IS_MPI | 
| 47 | 
– | 
#include <mpi.h> | 
| 48 | 
– | 
#endif | 
| 50 | 
  | 
 | 
| 51 | 
  | 
int nChecks; | 
| 52 | 
  | 
 | 
| 64 | 
  | 
  painCave.isEventLoop = 0; | 
| 65 | 
  | 
  nChecks = 0; | 
| 66 | 
  | 
#ifdef IS_MPI | 
| 67 | 
< | 
  MPI_Comm_rank( MPI_COMM_WORLD, &worldRank ); | 
| 67 | 
> | 
  worldRank = MPI::COMM_WORLD.Get_rank(); | 
| 68 | 
  | 
#else | 
| 69 | 
  | 
  worldRank = 0; | 
| 70 | 
  | 
#endif | 
| 72 | 
  | 
 | 
| 73 | 
  | 
int simError( void ) { | 
| 74 | 
  | 
   | 
| 75 | 
+ | 
  char errorMsg[MAX_SIM_ERROR_MSG_LENGTH]; | 
| 76 | 
+ | 
 | 
| 77 | 
+ | 
#ifdef IS_MPI | 
| 78 | 
  | 
  int myError = 1; | 
| 79 | 
  | 
  int isError; | 
| 76 | 
– | 
  char errorMsg[MAX_SIM_ERROR_MSG_LENGTH]; | 
| 80 | 
  | 
  char nodeMsg[MAX_SIM_ERROR_MSG_LENGTH]; | 
| 81 | 
+ | 
#endif | 
| 82 | 
  | 
   | 
| 83 | 
  | 
  strcpy(errorMsg, "OpenMD "); | 
| 84 | 
  | 
  switch( painCave.severity ) { | 
| 96 | 
  | 
  } | 
| 97 | 
  | 
   | 
| 98 | 
  | 
#ifdef IS_MPI | 
| 99 | 
< | 
  if ( painCave.isEventLoop ) { | 
| 100 | 
< | 
    sprintf( nodeMsg, " (reported by MPI node %d)", worldRank); | 
| 101 | 
< | 
    strncat(errorMsg, nodeMsg, strlen(nodeMsg)); | 
| 102 | 
< | 
  } | 
| 99 | 
> | 
  if (worldRank == 0) { | 
| 100 | 
> | 
    if ( painCave.isEventLoop ) { | 
| 101 | 
> | 
      sprintf( nodeMsg, " (reported by MPI node %d)", worldRank); | 
| 102 | 
> | 
      strncat(errorMsg, nodeMsg, strlen(nodeMsg)); | 
| 103 | 
> | 
    } | 
| 104 | 
  | 
#endif | 
| 105 | 
< | 
 | 
| 106 | 
< | 
  strcat(errorMsg, ":\n\t"); | 
| 107 | 
< | 
 | 
| 108 | 
< | 
  strncat(errorMsg, painCave.errMsg, strlen(painCave.errMsg)); | 
| 109 | 
< | 
 | 
| 110 | 
< | 
  strcat(errorMsg, "\n"); | 
| 111 | 
< | 
  fprintf(stderr, errorMsg); | 
| 112 | 
< | 
 | 
| 105 | 
> | 
     | 
| 106 | 
> | 
    strcat(errorMsg, ":\n\t"); | 
| 107 | 
> | 
     | 
| 108 | 
> | 
    strncat(errorMsg, painCave.errMsg, strlen(painCave.errMsg)); | 
| 109 | 
> | 
     | 
| 110 | 
> | 
    strcat(errorMsg, "\n"); | 
| 111 | 
> | 
    fprintf(stderr, "%s", errorMsg); | 
| 112 | 
> | 
     | 
| 113 | 
  | 
#ifdef IS_MPI | 
| 114 | 
< | 
  if (painCave.isEventLoop)  | 
| 115 | 
< | 
    return 1; | 
| 114 | 
> | 
    if (painCave.isEventLoop)  | 
| 115 | 
> | 
      return 1; | 
| 116 | 
> | 
  } | 
| 117 | 
  | 
#endif    | 
| 118 | 
  | 
 | 
| 119 | 
  | 
  if (painCave.isFatal) { | 
| 120 | 
  | 
#ifdef IS_MPI     | 
| 121 | 
< | 
    MPI_Allreduce( &myError, &isError, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD ); | 
| 122 | 
< | 
    MPI_Finalize(); | 
| 121 | 
> | 
    MPI::COMM_WORLD.Allreduce(&myError, &isError, 1, MPI::INT, MPI::LOR); | 
| 122 | 
> | 
    MPI::Finalize(); | 
| 123 | 
  | 
#endif | 
| 124 | 
  | 
    exit(0); | 
| 125 | 
< | 
  }  | 
| 120 | 
< | 
 | 
| 125 | 
> | 
  }   | 
| 126 | 
  | 
  return 1;   | 
| 127 | 
  | 
} | 
| 123 | 
– | 
  | 
| 128 | 
  | 
 | 
| 129 | 
+ | 
 | 
| 130 | 
  | 
void errorCheckPoint( void ){ | 
| 131 | 
< | 
     | 
| 131 | 
> | 
   | 
| 132 | 
  | 
  int myError = 0; | 
| 133 | 
  | 
  int isError = 0; | 
| 134 | 
< | 
 | 
| 134 | 
> | 
   | 
| 135 | 
  | 
#ifdef IS_MPI | 
| 136 | 
< | 
  MPI_Allreduce( &myError, &isError, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD ); | 
| 136 | 
> | 
  MPI::COMM_WORLD.Allreduce(&myError, &isError, 1, MPI::INT, MPI::LOR); | 
| 137 | 
  | 
#else | 
| 138 | 
  | 
  isError = myError; | 
| 139 | 
  | 
#endif | 
| 140 | 
< | 
 | 
| 141 | 
< | 
  if( isError ){ | 
| 137 | 
< | 
 | 
| 140 | 
> | 
   | 
| 141 | 
> | 
  if( isError ){     | 
| 142 | 
  | 
#ifdef IS_MPI | 
| 143 | 
< | 
    MPI_Finalize(); | 
| 144 | 
< | 
#endif | 
| 141 | 
< | 
 | 
| 143 | 
> | 
    MPI::Finalize(); | 
| 144 | 
> | 
#endif     | 
| 145 | 
  | 
    exit(0); | 
| 146 | 
  | 
  } | 
| 147 | 
< | 
 | 
| 147 | 
> | 
   | 
| 148 | 
  | 
#ifdef CHECKPOINT_VERBOSE   | 
| 149 | 
  | 
  nChecks++; | 
| 150 | 
  | 
 |