コード例 #1
0
ファイル: Log.cpp プロジェクト: bkkrueger/toy_hydro
   void write_all(std::string message) {
#ifdef PARALLEL_MPI
      // Declare variables
      int length, max_length;
      char *send_buf, *recv_buf;

      // MPI_Allreduce to determine length of longest message
      length = message.length();
      MPI_Allreduce(&length, &max_length, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);

      // Pad message to max_length
      message.resize(max_length, '\0');

      // Allocate a character array of max_length
      send_buf = (char*) message.c_str();
      recv_buf = new char[Driver::n_procs*max_length];

      // MPI_Gather the messages into a read buffer
      MPI_Gather(send_buf, max_length, MPI_CHAR,
                 recv_buf, max_length, MPI_CHAR, log_master, MPI_COMM_WORLD);

      // If you are the master:
      if (Driver::proc_ID == log_master) {
         // Parse the read buffer into individual messages
         for (int i = 0; i < Driver::n_procs; i++) {
            for (int j = 0; j < max_length; j++) {
               if (recv_buf[i*max_length+j] == '\0') {
                  break;
               }
               write_single(recv_buf[i*max_length+j]);
            }
         }
      }
#else // PARALLEL_MPI
      write_single(message);
#endif // PARALLEL_MPI
   }
コード例 #2
0
ファイル: Log.cpp プロジェクト: bkkrueger/toy_hydro
   void cleanup () {

      // Final printing
      write_single("\n" + std::string(79,'_') + "\nProgram Complete\n");

      if (initialized) {
         // If the log file is open, close it
#ifdef PARALLEL_MPI
         if (Driver::proc_ID == log_master) {
#endif // PARALLEL_MPI
            lout.close();
            initialized = false;
#ifdef PARALLEL_MPI
         }
#endif // PARALLEL_MPI
      } else {
         // If the log file was never opened, print the buffer to the screen
         std::cout << buffer.str();
         buffer.clear();
         buffer.str("");
      }

   }
コード例 #3
0
ファイル: modbus.c プロジェクト: andrewtholt/libmodbus-3.0.1
/* Writes a value in one register of the remote device */
int modbus_write_register(modbus_t *ctx, int addr, int value)
{
    return write_single(ctx, _FC_WRITE_SINGLE_REGISTER, addr, value);
}
コード例 #4
0
ファイル: modbus.c プロジェクト: andrewtholt/libmodbus-3.0.1
/* Turns ON or OFF a single bit of the remote device */
int modbus_write_bit(modbus_t *ctx, int addr, int status)
{
    return write_single(ctx, _FC_WRITE_SINGLE_COIL, addr,
                        status ? 0xFF00 : 0);
}