File: mpibig.cpp

package info (click to toggle)
wsclean 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,296 kB
  • sloc: cpp: 129,246; python: 22,066; sh: 360; ansic: 230; makefile: 185
file content (63 lines) | stat: -rw-r--r-- 2,143 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "mpibig.h"

#include <aocommon/logger.h>

#include <algorithm>
#include <cstdint>

using aocommon::Logger;

namespace wsclean {

int MPI_Send_Big(unsigned char* buf, size_t count, int dest, int tag,
                 MPI_Comm comm, size_t maximum_message_size) {
  size_t n_packages = (count + maximum_message_size - 1) / maximum_message_size;

  *reinterpret_cast<uint64_t*>(buf) = n_packages;

  Logger::Debug << "Sending " << n_packages << " packages...\n";
  for (size_t i = 0; i != n_packages - 1; ++i) {
    const unsigned char* part_buffer = buf + i * maximum_message_size;
    int return_value =
        MPI_Send(part_buffer, maximum_message_size, MPI_BYTE, dest, tag, comm);
    if (return_value != MPI_SUCCESS) return return_value;
    Logger::Debug << "Package " << (i + 1) << " sent.\n";
  }

  const unsigned char* part_buffer =
      buf + (n_packages - 1) * maximum_message_size;
  size_t part_count = count % maximum_message_size;
  int return_value =
      MPI_Send(part_buffer, part_count, MPI_BYTE, dest, tag, comm);
  Logger::Debug << "Package " << n_packages << " sent.\n";
  return return_value;
}

int MPI_Recv_Big(unsigned char* buf, size_t count, int source, int tag,
                 MPI_Comm comm, MPI_Status* status,
                 size_t maximum_message_size) {
  int first_size = std::min(maximum_message_size, count);
  int return_value =
      MPI_Recv(buf, first_size, MPI_BYTE, source, tag, comm, status);
  if (return_value != MPI_SUCCESS) return return_value;

  size_t n_packages = *reinterpret_cast<uint64_t*>(buf);
  buf += first_size;
  count -= size_t(first_size);

  Logger::Debug << "Received package 1/" << n_packages << ".\n";
  for (size_t i = 1; i != n_packages; ++i) {
    int part_size = std::min(maximum_message_size, count);
    return_value =
        MPI_Recv(buf, part_size, MPI_BYTE, source, tag, comm, status);
    if (return_value != MPI_SUCCESS) return return_value;

    buf += part_size;
    count -= size_t(part_size);
    Logger::Debug << "Received package " << (i + 1) << "/" << n_packages
                  << ".\n";
  }
  return MPI_SUCCESS;
}

}  // namespace wsclean