Debian Codegraph @

src/atlas/parallel/Checksum.cc

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #include <cstring>
12
13 #include "atlas/parallel/Checksum.h"
14
15 namespace atlas {
16 namespace parallel {
17
18 Checksum::Checksum(): name_() {
19 is_setup_ = false;
20 }
21
22 Checksum::Checksum(const std::string& name): name_(name) {
23 is_setup_ = false;
24 }
25
26 void Checksum::setup(const std::string& mpi_comm, const int part[], const idx_t remote_idx[], const int base, const gidx_t glb_idx[],
27 const int parsize) {
28 parsize_ = parsize;
29 gather_ = util::ObjectHandle<GatherScatter>(new GatherScatter());
30 gather_->setup(mpi_comm, part, remote_idx, base, glb_idx, parsize);
31 is_setup_ = true;
32 }
33
34 void Checksum::setup(const int part[], const idx_t remote_idx[], const int base, const gidx_t glb_idx[],
35 const int parsize) {
36 setup(mpi::comm().name(), part, remote_idx, base, glb_idx, parsize);
37 }
38
39 void Checksum::setup(const std::string& mpi_comm, const int part[], const idx_t remote_idx[], const int base, const gidx_t glb_idx[],
40 const int mask[], const int parsize) {
41 parsize_ = parsize;
42 gather_ = util::ObjectHandle<GatherScatter>(new GatherScatter());
43 gather_->setup(mpi_comm, part, remote_idx, base, glb_idx, mask, parsize);
44 is_setup_ = true;
45 }
46
47 void Checksum::setup(const int part[], const idx_t remote_idx[], const int base, const gidx_t glb_idx[],
48 const int mask[], const int parsize) {
49 setup(mpi::comm().name(), part, remote_idx, base, glb_idx, mask, parsize);
50 }
51
52 void Checksum::setup(const util::ObjectHandle<GatherScatter>& gather) {
53 gather_ = gather;
54 parsize_ = gather->parsize_;
55 is_setup_ = true;
56 }
57
58 /////////////////////
59
60 Checksum* atlas__Checksum__new() {
61 return new Checksum();
62 }
63
64 void atlas__Checksum__delete(Checksum* This) {
65 delete This;
66 }
67
68 void atlas__Checksum__setup32(Checksum* This, int part[], idx_t remote_idx[], int base, int glb_idx[], int parsize) {
69 #if ATLAS_BITS_GLOBAL == 32
70 This->setup(part, remote_idx, base, glb_idx, parsize);
71 #else
72 std::vector<gidx_t> glb_idx_convert(parsize);
73 for (int j = 0; j < parsize; ++j) {
74 glb_idx_convert[j] = glb_idx[j];
75 }
76 This->setup(part, remote_idx, base, glb_idx_convert.data(), parsize);
77 #endif
78 }
79
80 void atlas__Checksum__setup64(Checksum* This, int part[], idx_t remote_idx[], int base, long glb_idx[], int parsize) {
81 #if ATLAS_BITS_GLOBAL == 64
82 This->setup(part, remote_idx, base, glb_idx, parsize);
83 #else
84 std::vector<gidx_t> glb_idx_convert(parsize);
85 for (int j = 0; j < parsize; ++j) {
86 glb_idx_convert[j] = glb_idx[j];
87 }
88 This->setup(part, remote_idx, base, glb_idx_convert.data(), parsize);
89 #endif
90 }
91
92 void atlas__Checksum__execute_strided_int(Checksum* This, int lfield[], int lvar_strides[], int lvar_extents[],
93 int lvar_rank, char* checksum) {
94 std::strcpy(checksum, This->execute(lfield, lvar_strides, lvar_extents, lvar_rank).c_str());
95 }
96
97 void atlas__Checksum__execute_strided_float(Checksum* This, float lfield[], int lvar_strides[], int lvar_extents[],
98 int lvar_rank, char* checksum) {
99 std::strcpy(checksum, This->execute(lfield, lvar_strides, lvar_extents, lvar_rank).c_str());
100 }
101
102 void atlas__Checksum__execute_strided_double(Checksum* This, double lfield[], int lvar_strides[], int lvar_extents[],
103 int lvar_rank, char* checksum) {
104 std::strcpy(checksum, This->execute(lfield, lvar_strides, lvar_extents, lvar_rank).c_str());
105 }
106
107 void atlas__Checksum__execute_strided_long(Checksum* This, long lfield[], int lvar_strides[], int lvar_extents[],
108 int lvar_rank, char* checksum) {
109 std::strcpy(checksum, This->execute(lfield, lvar_strides, lvar_extents, lvar_rank).c_str());
110 }
111
112 // const char* atlas__Checksum__execute_strided_double (Checksum* This,
113 // double lfield[], int
114 // lvar_strides[], int
115 // lvar_extents[], int lvar_rank)
116 //{
117 // std::string checksum =
118 // This->execute(lfield,lvar_strides,lvar_extents,lvar_rank);
119 // return checksum.c_str();
120 //}
121
122 /////////////////////
123
124 } // namespace parallel
125 } // namespace atlas