| 1 | #include "MBInterface.hpp" |
|---|
| 2 | #include "MBParallelComm.hpp" |
|---|
| 3 | #include "MBWriteUtilIface.hpp" |
|---|
| 4 | #include "MBReadUtilIface.hpp" |
|---|
| 5 | #include "SequenceManager.hpp" |
|---|
| 6 | #include "EntitySequence.hpp" |
|---|
| 7 | #include "TagServer.hpp" |
|---|
| 8 | #include "MBTagConventions.hpp" |
|---|
| 9 | #include "MBSkinner.hpp" |
|---|
| 10 | #include "MBParallelConventions.h" |
|---|
| 11 | #include "MBCore.hpp" |
|---|
| 12 | #include "MBError.hpp" |
|---|
| 13 | #include "ElementSequence.hpp" |
|---|
| 14 | #include "MBCN.hpp" |
|---|
| 15 | #include "RangeMap.hpp" |
|---|
| 16 | |
|---|
| 17 | #include <iostream> |
|---|
| 18 | #include <algorithm> |
|---|
| 19 | #include <numeric> |
|---|
| 20 | |
|---|
| 21 | #define MIN(a,b) (a < b ? a : b) |
|---|
| 22 | #define MAX(a,b) (a > b ? a : b) |
|---|
| 23 | const bool debug = false; |
|---|
| 24 | const bool debug_packing = false; |
|---|
| 25 | |
|---|
| 26 | #include <math.h> |
|---|
| 27 | #include <assert.h> |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | extern "C" |
|---|
| 31 | { |
|---|
| 32 | #include "minmax.h" |
|---|
| 33 | #include "gs.h" |
|---|
| 34 | #include "errmem.h" |
|---|
| 35 | #include "types.h" |
|---|
| 36 | #include "sort.h" |
|---|
| 37 | #include "tuple_list.h" |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | #ifdef USE_MPI |
|---|
| 41 | #include "mpi.h" |
|---|
| 42 | #endif |
|---|
| 43 | |
|---|
| 44 | const int INITIAL_BUFF_SIZE = 1024; |
|---|
| 45 | const int MAX_BCAST_SIZE = (1<<28); |
|---|
| 46 | |
|---|
| 47 | //#define DEBUG_PACKING 1 |
|---|
| 48 | #ifdef DEBUG_PACKING |
|---|
| 49 | unsigned int __PACK_num = 0, __UNPACK_num = 0, __PACK_count = 0, __UNPACK_count = 0; |
|---|
| 50 | std::string __PACK_string, __UNPACK_string; |
|---|
| 51 | |
|---|
| 52 | #define PC(n, m) {\ |
|---|
| 53 | Â Â Â Â Â if (__PACK_num == (unsigned int)n && __PACK_string == m) __PACK_count++;\ |
|---|
| 54 | Â Â Â Â Â else {\ |
|---|
| 55 | Â Â Â Â Â Â if (__PACK_count > 1) std::cerr << " (" << __PACK_count << "x)";\ |
|---|
| 56 | Â Â Â Â Â Â __PACK_count = 1; __PACK_string = m; __PACK_num = n;\ |
|---|
| 57 | Â Â Â Â Â Â std::cerr << std::endl << "PACK: " << n << m;\ |
|---|
| 58 | Â Â Â Â Â }} |
|---|
| 59 | #define UPC(n, m) {\ |
|---|
| 60 | Â Â Â Â Â if (__UNPACK_num == (unsigned int)n && __UNPACK_string == m) __UNPACK_count++;\ |
|---|
| 61 | Â Â Â Â Â else {\ |
|---|
| 62 | Â Â Â Â Â Â if (__UNPACK_count > 1) std::cerr << "(" << __UNPACK_count << "x)";\ |
|---|
| 63 | Â Â Â Â Â Â __UNPACK_count = 1; __UNPACK_string = m; __UNPACK_num = n;\ |
|---|
| 64 | Â Â Â Â Â Â std::cerr << std::endl << "UNPACK: " << n << m;\ |
|---|
| 65 | Â Â Â Â Â }} |
|---|
| 66 | #else |
|---|
| 67 | #define PC(n, m) |
|---|
| 68 | #define UPC(n, m) |
|---|
| 69 | #endif |
|---|
| 70 | |
|---|
| 71 | #define PACK_INT(buff, int_val) {int tmp_val = int_val; PACK_INTS(buff, &tmp_val, 1);} |
|---|
| 72 | |
|---|
| 73 | #define PACK_INTS(buff, int_val, num) {memcpy(buff, int_val, (num)*sizeof(int)); buff += (num)*sizeof(int); PC(num, " ints");} |
|---|
| 74 | |
|---|
| 75 | #define PACK_DBL(buff, dbl_val, num) {memcpy(buff, dbl_val, (num)*sizeof(double)); buff += (num)*sizeof(double); PC(num, " doubles");} |
|---|
| 76 | |
|---|
| 77 | #define PACK_EH(buff, eh_val, num) {memcpy(buff, eh_val, (num)*sizeof(MBEntityHandle)); buff += (num)*sizeof(MBEntityHandle); PC(num, " handles");} |
|---|
| 78 | |
|---|
| 79 | #define PACK_CHAR_64(buff, char_val) {strcpy((char*)buff, char_val); buff += 64; PC(64, " chars");} |
|---|
| 80 | |
|---|
| 81 | #define PACK_VOID(buff, val, num) {memcpy(buff, val, num); buff += num; PC(num, " void");} |
|---|
| 82 | |
|---|
| 83 | #define PACK_BYTES(buff, val, num) PACK_INT(buff, num) PACK_VOID(buff, val, num) |
|---|
| 84 | |
|---|
| 85 | #define PACK_RANGE(buff, rng) {int num_subs = num_subranges(rng); PACK_INTS(buff, &num_subs, 1); PC(num_subs, "-subranged range"); \ |
|---|
| 86 | Â Â Â Â Â for (MBRange::const_pair_iterator cit = rng.const_pair_begin(); cit != rng.const_pair_end(); cit++) { \ |
|---|
| 87 | Â Â Â Â Â Â MBEntityHandle eh = (*cit).first; PACK_EH(buff, &eh, 1); \ |
|---|
| 88 | Â Â Â Â Â Â eh = (*cit).second; PACK_EH(buff, &eh, 1);}; } |
|---|
| 89 | |
|---|
| 90 | #define UNPACK_INT(buff, int_val) {UNPACK_INTS(buff, &int_val, 1);} |
|---|
| 91 | |
|---|
| 92 | #define UNPACK_INTS(buff, int_val, num) {memcpy(int_val, buff, (num)*sizeof(int)); buff += (num)*sizeof(int); UPC(num, " ints");} |
|---|
| 93 | |
|---|
| 94 | #define UNPACK_DBL(buff, dbl_val, num) {memcpy(dbl_val, buff, (num)*sizeof(double)); buff += (num)*sizeof(double); UPC(num, " doubles");} |
|---|
| 95 | |
|---|
| 96 | #define UNPACK_EH(buff, eh_val, num) {memcpy(eh_val, buff, (num)*sizeof(MBEntityHandle)); buff += (num)*sizeof(MBEntityHandle); UPC(num, " handles");} |
|---|
| 97 | |
|---|
| 98 | #define UNPACK_CHAR_64(buff, char_val) {strcpy(char_val, (char*)buff); buff += 64; UPC(64, " chars");} |
|---|
| 99 | |
|---|
| 100 | #define UNPACK_VOID(buff, val, num) {memcpy(val, buff, num); buff += num; UPC(num, " void");} |
|---|
| 101 | |
|---|
| 102 | #define UNPACK_RANGE(buff, rng) {int num_subs; UNPACK_INTS(buff, &num_subs, 1); UPC(num_subs, "-subranged range"); MBEntityHandle _eh[2]; \ |
|---|
| 103 | Â Â Â Â Â for (int i = 0; i < num_subs; i++) { UNPACK_EH(buff, _eh, 2); rng.insert(_eh[0], _eh[1]);}} |
|---|
| 104 | |
|---|
| 105 | #define RR(a) if (MB_SUCCESS != result) {\ |
|---|
| 106 | Â Â Â Â Â dynamic_cast<MBCore*>(mbImpl)->get_error_handler()->set_last_error(a);\ |
|---|
| 107 | Â Â Â Â Â return result;} |
|---|
| 108 | |
|---|
| 109 | #define RRA(a) if (MB_SUCCESS != result) {\ |
|---|
| 110 | Â Â Â std::string tmp_str; mbImpl->get_last_error(tmp_str);\ |
|---|
| 111 | Â Â Â tmp_str.append("\n"); tmp_str.append(a);\ |
|---|
| 112 | Â Â Â dynamic_cast<MBCore*>(mbImpl)->get_error_handler()->set_last_error(tmp_str.c_str()); \ |
|---|
| 113 | Â Â Â return result;} |
|---|
| 114 | |
|---|
| 115 | /** Name of tag used to store MBParallelComm Index on mesh paritioning sets */ |
|---|
| 116 | const char* PARTITIONING_PCOMM_TAG_NAME = "__PRTN_PCOMM"; |
|---|
| 117 | Â |
|---|
| 118 | /** \brief Tag storing parallel communication objects |
|---|
| 119 | Â * |
|---|
| 120 | Â * This tag stores pointers to MBParallelComm communication |
|---|
| 121 | Â * objects; one of these is allocated for each different |
|---|
| 122 |  * communicator used to read mesh. MBParallelComm stores |
|---|
| 123 | Â * partition and interface sets corresponding to its parallel mesh. |
|---|
| 124 | Â * By default, a parallel read uses the first MBParallelComm object |
|---|
| 125 | Â * on the interface instance; if instantiated with one, ReadParallel |
|---|
| 126 | Â * adds this object to the interface instance too. |
|---|
| 127 | Â * |
|---|
| 128 | Â * Tag type: opaque |
|---|
| 129 | Â * Tag size: MAX_SHARING_PROCS*sizeof(MBParallelComm*) |
|---|
| 130 | Â */ |
|---|
| 131 | #define PARALLEL_COMM_TAG_NAME "__PARALLEL_COMM" |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | enum MBMessageTag {MB_MESG_ANY=MPI_ANY_TAG, |
|---|
| 135 | Â Â Â Â Â Â Â Â Â Â MB_MESG_SIZE, |
|---|
| 136 | Â Â Â Â Â Â Â Â Â Â MB_MESG_ENTS, |
|---|
| 137 | Â Â Â Â Â Â Â Â Â Â MB_MESG_REMOTE_HANDLES_RANGE, |
|---|
| 138 | Â Â Â Â Â Â Â Â Â Â MB_MESG_REMOTE_HANDLES_VECTOR, |
|---|
| 139 | Â Â Â Â Â Â Â Â Â Â MB_MESG_TAGS }; |
|---|
| 140 | Â Â |
|---|
| 141 | MBParallelComm::MBParallelComm(MBInterface *impl, MPI_Comm comm, int* id ) |
|---|
| 142 |   : mbImpl(impl), procConfig(comm), sharedpTag(0), sharedpsTag(0), |
|---|
| 143 |    sharedhTag(0), sharedhsTag(0), pstatusTag(0), ifaceSetsTag(0), |
|---|
| 144 |    partitionTag(0), globalPartCount(-1), partitioningSet(0) |
|---|
| 145 | { |
|---|
| 146 | Â myBuffer.resize(INITIAL_BUFF_SIZE); |
|---|
| 147 | |
|---|
| 148 | Â tagServer =Â dynamic_cast<MBCore*>(mbImpl)->tag_server(); |
|---|
| 149 | Â sequenceManager =Â dynamic_cast<MBCore*>(mbImpl)->sequence_manager(); |
|---|
| 150 | |
|---|
| 151 |  int flag = 1; |
|---|
| 152 |  int retval = MPI_Initialized(&flag); |
|---|
| 153 |  if (MPI_SUCCESS != retval || !flag) { |
|---|
| 154 |   int argc = 0; |
|---|
| 155 |   char **argv = NULL; |
|---|
| 156 | Â Â |
|---|
| 157 | Â Â Â // mpi not initialized yet - initialize here |
|---|
| 158 |   retval = MPI_Init(&argc, &argv); |
|---|
| 159 | Â } |
|---|
| 160 | |
|---|
| 161 | Â pcommID =Â add_pcomm(this); |
|---|
| 162 |  if (id) |
|---|
| 163 | Â Â *id =Â pcommID; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | MBParallelComm::MBParallelComm(MBInterface *impl, |
|---|
| 167 |                 std::vector<unsigned char> &tmp_buff, |
|---|
| 168 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MPI_Comm comm, |
|---|
| 169 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â int*Â id)Â |
|---|
| 170 |   : mbImpl(impl), procConfig(comm), sharedpTag(0), sharedpsTag(0), |
|---|
| 171 |    sharedhTag(0), sharedhsTag(0), pstatusTag(0), ifaceSetsTag(0), |
|---|
| 172 |    partitionTag(0), globalPartCount(-1), partitioningSet(0) |
|---|
| 173 | { |
|---|
| 174 | Â myBuffer.swap(tmp_buff); |
|---|
| 175 |  int flag = 1; |
|---|
| 176 |  int retval = MPI_Initialized(&flag); |
|---|
| 177 |  if (MPI_SUCCESS != retval || !flag) { |
|---|
| 178 |   int argc = 0; |
|---|
| 179 |   char **argv = NULL; |
|---|
| 180 | Â Â |
|---|
| 181 | Â Â Â // mpi not initialized yet - initialize here |
|---|
| 182 |   retval = MPI_Init(&argc, &argv); |
|---|
| 183 | Â } |
|---|
| 184 | |
|---|
| 185 | Â pcommID =Â add_pcomm(this); |
|---|
| 186 |  if (id) |
|---|
| 187 | Â Â *id =Â pcommID; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | MBParallelComm::~MBParallelComm()Â |
|---|
| 191 | { |
|---|
| 192 | Â remove_pcomm(this); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | int MBParallelComm::add_pcomm(MBParallelComm *pc) |
|---|
| 196 | { |
|---|
| 197 | Â Â // add this pcomm to instance tag |
|---|
| 198 |  std::vector<MBParallelComm *> pc_array(MAX_SHARING_PROCS, |
|---|
| 199 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (MBParallelComm*)NULL); |
|---|
| 200 |  MBTag pc_tag = pcomm_tag(mbImpl, true); |
|---|
| 201 | Â assert(0Â !=Â pc_tag); |
|---|
| 202 | Â |
|---|
| 203 |  MBErrorCode result = mbImpl->tag_get_data(pc_tag, 0, 0, (void*)&pc_array[0]); |
|---|
| 204 |  if (MB_SUCCESS != result && MB_TAG_NOT_FOUND != result) |
|---|
| 205 |   return -1; |
|---|
| 206 |  int index = 0; |
|---|
| 207 |  while (index < MAX_SHARING_PROCS && pc_array[index]) index++; |
|---|
| 208 |  if (index == MAX_SHARING_PROCS) { |
|---|
| 209 | Â Â index =Â -1; |
|---|
| 210 | Â Â assert(false); |
|---|
| 211 | Â } |
|---|
| 212 |  else { |
|---|
| 213 | Â Â pc_array[index]Â =Â pc; |
|---|
| 214 |   mbImpl->tag_set_data(pc_tag, 0, 0, (void*)&pc_array[0]); |
|---|
| 215 | Â } |
|---|
| 216 |  return index; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | void MBParallelComm::remove_pcomm(MBParallelComm *pc) |
|---|
| 220 | { |
|---|
| 221 | Â Â // remove this pcomm from instance tag |
|---|
| 222 | Â std::vector<MBParallelComm *>Â pc_array(MAX_SHARING_PROCS); |
|---|
| 223 |  MBTag pc_tag = pcomm_tag(mbImpl, true); |
|---|
| 224 | Â |
|---|
| 225 |  MBErrorCode result = mbImpl->tag_get_data(pc_tag, 0, 0, (void*)&pc_array[0]); |
|---|
| 226 | Â std::vector<MBParallelComm*>::iterator pc_it =Â |
|---|
| 227 |   std::find(pc_array.begin(), pc_array.end(), pc); |
|---|
| 228 | Â assert(MB_SUCCESS ==Â result &&Â |
|---|
| 229 | Â Â Â Â Â pc_it !=Â pc_array.end()); |
|---|
| 230 | Â *pc_it =Â NULL; |
|---|
| 231 |  mbImpl->tag_set_data(pc_tag, 0, 0, (void*)&pc_array[0]); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | //! assign a global id space, for largest-dimension or all entities (and |
|---|
| 235 | //! in either case for vertices too) |
|---|
| 236 | MBErrorCode MBParallelComm::assign_global_ids(MBEntityHandle this_set, |
|---|
| 237 |                        const int dimension, |
|---|
| 238 |                        const int start_id, |
|---|
| 239 |                        const bool largest_dim_only, |
|---|
| 240 |                        const bool parallel) |
|---|
| 241 | { |
|---|
| 242 | Â MBRange entities[4]; |
|---|
| 243 |  int local_num_elements[4]; |
|---|
| 244 | Â MBErrorCode result; |
|---|
| 245 |  std::vector<unsigned char> pstatus; |
|---|
| 246 |  for (int dim = 0; dim <= dimension; dim++) { |
|---|
| 247 |   if (dim == 0 || !largest_dim_only || dim == dimension) { |
|---|
| 248 |    result = mbImpl->get_entities_by_dimension(this_set, dim, entities[dim]); |
|---|
| 249 | Â Â Â RRA("Failed to get vertices in assign_global_ids."); |
|---|
| 250 | Â Â } |
|---|
| 251 | |
|---|
| 252 | Â Â Â // need to filter out non-locally-owned entities!!! |
|---|
| 253 | Â Â pstatus.resize(entities[dim].size()); |
|---|
| 254 |   result = mbImpl->tag_get_data(pstatus_tag(), entities[dim], &pstatus[0]); |
|---|
| 255 | Â Â RRA("Failed to get pstatus in assign_global_ids."); |
|---|
| 256 | Â Â |
|---|
| 257 | Â Â MBRange dum_range; |
|---|
| 258 | Â Â MBRange::iterator rit; |
|---|
| 259 |   unsigned int i; |
|---|
| 260 |   for (rit = entities[dim].begin(), i = 0; rit != entities[dim].end(); rit++, i++) |
|---|
| 261 |    if (pstatus[i] & PSTATUS_NOT_OWNED) |
|---|
| 262 | Â Â Â Â dum_range.insert(*rit); |
|---|
| 263 | Â Â entities[dim]Â =Â entities[dim].subtract(dum_range); |
|---|
| 264 | Â Â |
|---|
| 265 | Â Â local_num_elements[dim]Â =Â entities[dim].size(); |
|---|
| 266 | Â } |
|---|
| 267 | Â |
|---|
| 268 | Â Â // communicate numbers |
|---|
| 269 | Â std::vector<int>Â num_elements(procConfig.proc_size()*4); |
|---|
| 270 | #ifdef USE_MPI |
|---|
| 271 |  if (procConfig.proc_size() > 1 && parallel) { |
|---|
| 272 |   int retval = MPI_Alltoall(local_num_elements, 4, MPI_INT, |
|---|
| 273 |                &num_elements[0], procConfig.proc_size()*4, |
|---|
| 274 |                MPI_INT, procConfig.proc_comm()); |
|---|
| 275 |   if (0 != retval) return MB_FAILURE; |
|---|
| 276 | Â } |
|---|
| 277 | Â else |
|---|
| 278 | #endif |
|---|
| 279 |   for (int dim = 0; dim < 4; dim++) num_elements[dim] = local_num_elements[dim]; |
|---|
| 280 | Â |
|---|
| 281 | Â Â // my entities start at one greater than total_elems[d] |
|---|
| 282 |  int total_elems[4] = {start_id, start_id, start_id, start_id}; |
|---|
| 283 | Â |
|---|
| 284 |  for (unsigned int proc = 0; proc < procConfig.proc_rank(); proc++) { |
|---|
| 285 |   for (int dim = 0; dim < 4; dim++) total_elems[dim] += num_elements[4*proc + dim]; |
|---|
| 286 | Â } |
|---|
| 287 | Â |
|---|
| 288 | Â Â //assign global ids now |
|---|
| 289 | Â MBTag gid_tag; |
|---|
| 290 |  int zero = 0; |
|---|
| 291 |  result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int), |
|---|
| 292 |                MB_TAG_DENSE, MB_TYPE_INTEGER, gid_tag, |
|---|
| 293 |                &zero, true); |
|---|
| 294 |  if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) return result; |
|---|
| 295 | Â |
|---|
| 296 |  for (int dim = 0; dim < 4; dim++) { |
|---|
| 297 |   if (entities[dim].empty()) continue; |
|---|
| 298 | Â Â num_elements.resize(entities[dim].size()); |
|---|
| 299 |   int i = 0; |
|---|
| 300 |   for (MBRange::iterator rit = entities[dim].begin(); rit != entities[dim].end(); rit++) |
|---|
| 301 | Â Â Â num_elements[i++]Â =Â total_elems[dim]++; |
|---|
| 302 | Â Â |
|---|
| 303 |   result = mbImpl->tag_set_data(gid_tag, entities[dim], &num_elements[0]); |
|---|
| 304 | Â Â RRA("Failed to set global id tag in assign_global_ids."); |
|---|
| 305 | Â } |
|---|
| 306 | Â |
|---|
| 307 |  return MB_SUCCESS; |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | MBErrorCode MBParallelComm::send_entities(const int to_proc, |
|---|
| 311 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &orig_ents, |
|---|
| 312 |                      const bool adjs, |
|---|
| 313 |                      const bool tags, |
|---|
| 314 |                      const bool store_remote_handles, |
|---|
| 315 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &final_ents, |
|---|
| 316 |                      bool wait_all) |
|---|
| 317 | { |
|---|
| 318 | |
|---|
| 319 | Â Â // find a spot in the proc buffers vector |
|---|
| 320 |  int index = get_buffers(to_proc); |
|---|
| 321 | Â |
|---|
| 322 | Â Â // pack/send the entities to the destination |
|---|
| 323 |  MPI_Request req_vec[2] = {MPI_REQUEST_NULL, // send req (ownerSBuff) |
|---|
| 324 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MPI_REQUEST_NULL};Â // recv req (remote handles) |
|---|
| 325 |  MBErrorCode result = pack_send_entities(to_proc, orig_ents, |
|---|
| 326 |                      adjs, tags, store_remote_handles, false, |
|---|
| 327 |                      ownerSBuffs[index], ownerRBuffs[index], |
|---|
| 328 |                      req_vec[0], req_vec[1], final_ents); |
|---|
| 329 | Â RRA("Failed to pack-send entities."); |
|---|
| 330 | |
|---|
| 331 | Â MPI_Status statuses[2]; |
|---|
| 332 | |
|---|
| 333 | Â Â // if we're storing remote handles, process the return message |
|---|
| 334 |  if (store_remote_handles) { |
|---|
| 335 | Â Â assert(MPI_REQUEST_NULL !=Â req_vec[1]); |
|---|
| 336 |   MPI_Wait(&req_vec[1], &statuses[1]); |
|---|
| 337 | Â Â MBRange remote_range; |
|---|
| 338 |   unsigned char *buff_ptr = &ownerRBuffs[index][0]; |
|---|
| 339 |   UNPACK_RANGE(buff_ptr, remote_range); |
|---|
| 340 |   result = set_remote_data(final_ents, remote_range, to_proc); |
|---|
| 341 | Â Â RRA("Trouble setting remote data range on sent entities."); |
|---|
| 342 | Â } |
|---|
| 343 | |
|---|
| 344 |  if (wait_all) { |
|---|
| 345 | Â Â Â // wait for all to finish |
|---|
| 346 |   int success = MPI_Waitall(2, req_vec, statuses); |
|---|
| 347 |   if (success != MPI_SUCCESS) { |
|---|
| 348 | Â Â Â result =Â MB_FAILURE; |
|---|
| 349 | Â Â Â RRA("Failed in waitall in send_entities."); |
|---|
| 350 | Â Â } |
|---|
| 351 | Â } |
|---|
| 352 | Â |
|---|
| 353 |  return MB_SUCCESS; |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | MBErrorCode MBParallelComm::recv_entities(const int from_proc, |
|---|
| 357 |                      const bool store_remote_handles, |
|---|
| 358 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &final_ents, |
|---|
| 359 |                      bool wait_all) |
|---|
| 360 | { |
|---|
| 361 | Â MBErrorCode result; |
|---|
| 362 | Â |
|---|
| 363 | Â Â // find a spot in the proc buffers vector |
|---|
| 364 |  int index = get_buffers(from_proc); |
|---|
| 365 | Â |
|---|
| 366 | Â Â // recv/unpack entities from the sender |
|---|
| 367 | Â MPI_Request req =Â MPI_REQUEST_NULL; |
|---|
| 368 | Â MPI_Status status; |
|---|
| 369 |  int success = MPI_Recv(&ghostRBuffs[index][0], ghostRBuffs[index].size(), |
|---|
| 370 |              MPI_UNSIGNED_CHAR, from_proc, |
|---|
| 371 |              MB_MESG_ANY, procConfig.proc_comm(), |
|---|
| 372 | Â Â Â Â Â Â Â Â Â Â Â Â Â &status); |
|---|
| 373 |  if (MPI_SUCCESS != success) { |
|---|
| 374 | Â Â result =Â MB_FAILURE; |
|---|
| 375 | Â Â RRA("Recv failed in recv_ents."); |
|---|
| 376 | Â } |
|---|
| 377 | |
|---|
| 378 | Â Â // check type, and if it's just the size, resize buffer and re-call recv |
|---|
| 379 |  if (MB_MESG_SIZE == status.MPI_TAG) { |
|---|
| 380 | Â Â result =Â recv_size_buff(from_proc, |
|---|
| 381 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â ghostRBuffs[index], |
|---|
| 382 |               req, MB_MESG_ANY); |
|---|
| 383 | Â Â RRA("Failed to resize recv buffer."); |
|---|
| 384 |   MPI_Wait(&req, &status); |
|---|
| 385 | Â } |
|---|
| 386 | Â |
|---|
| 387 | Â Â // ok, got the actual entities, now unpack |
|---|
| 388 |  result = recv_unpack_entities(from_proc, store_remote_handles, false, |
|---|
| 389 |                 ghostRBuffs[index], ghostSBuffs[index], |
|---|
| 390 |                 req, final_ents); |
|---|
| 391 | Â RRA("Failed to recv-unpack message."); |
|---|
| 392 | |
|---|
| 393 |  if (wait_all) { |
|---|
| 394 | Â Â Â // wait for last message to finish |
|---|
| 395 |   int success = MPI_Wait(&req, &status); |
|---|
| 396 |   if (success != MPI_SUCCESS) { |
|---|
| 397 | Â Â Â result =Â MB_FAILURE; |
|---|
| 398 | Â Â Â RRA("Failed in wait in recv_entities."); |
|---|
| 399 | Â Â } |
|---|
| 400 | Â } |
|---|
| 401 | |
|---|
| 402 |  return result; |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | int MBParallelComm::get_buffers(int to_proc) |
|---|
| 406 | { |
|---|
| 407 |  int ind = -1; |
|---|
| 408 | Â std::vector<int>::iterator vit =Â |
|---|
| 409 |   std::find(buffProcs.begin(), buffProcs.end(), to_proc); |
|---|
| 410 |  if (vit == buffProcs.end()) { |
|---|
| 411 | Â Â ind =Â buffProcs.size(); |
|---|
| 412 | Â Â buffProcs.push_back(to_proc); |
|---|
| 413 | Â Â ownerSBuffs[ind].resize(INITIAL_BUFF_SIZE); |
|---|
| 414 | Â Â ghostRBuffs[ind].resize(INITIAL_BUFF_SIZE); |
|---|
| 415 | Â Â Â // allocate these other buffs in case we're storing remote handles |
|---|
| 416 | Â Â ownerRBuffs[ind].resize(INITIAL_BUFF_SIZE); |
|---|
| 417 | Â Â ghostSBuffs[ind].resize(INITIAL_BUFF_SIZE); |
|---|
| 418 | Â Â Â |
|---|
| 419 | Â } |
|---|
| 420 |  else ind = vit - buffProcs.begin(); |
|---|
| 421 | Â assert(ind <Â MAX_SHARING_PROCS); |
|---|
| 422 |  return ind; |
|---|
| 423 | } |
|---|
| 424 | |
|---|
| 425 | MBErrorCode MBParallelComm::pack_send_entities(const int to_proc, |
|---|
| 426 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &orig_ents, |
|---|
| 427 |                         const bool adjacencies, |
|---|
| 428 |                         const bool tags, |
|---|
| 429 |                         const bool store_remote_handles, |
|---|
| 430 |                         const bool iface_layer, |
|---|
| 431 |                         std::vector<unsigned char> &send_buff, |
|---|
| 432 |                         std::vector<unsigned char> &recv_buff, |
|---|
| 433 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MPI_Request &send_req, |
|---|
| 434 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MPI_Request &recv_req, |
|---|
| 435 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &final_ents)Â |
|---|
| 436 | { |
|---|
| 437 | #ifndef USE_MPI |
|---|
| 438 |  return MB_FAILURE; |
|---|
| 439 | #else |
|---|
| 440 | |
|---|
| 441 | Â MBErrorCode result =Â MB_SUCCESS; |
|---|
| 442 | Â MBRange whole_range; |
|---|
| 443 |  int buff_size; |
|---|
| 444 | Â Â |
|---|
| 445 |  result = pack_buffer(orig_ents, adjacencies, tags, |
|---|
| 446 |             store_remote_handles, iface_layer, to_proc, |
|---|
| 447 |             final_ents, send_buff, buff_size); |
|---|
| 448 | Â RRA("Failed to pack buffer in pack_send."); |
|---|
| 449 | |
|---|
| 450 | Â Â // now that we know how many entities, post a receive for the |
|---|
| 451 | Â Â // remote range, if requested |
|---|
| 452 |  int success; |
|---|
| 453 |  if (store_remote_handles && iface_layer) { |
|---|
| 454 | Â Â recv_buff.resize(final_ents.size()*sizeof(MBEntityHandle)Â +Â sizeof(int)); |
|---|
| 455 | Â Â |
|---|
| 456 |   success = MPI_Irecv(&recv_buff[0], recv_buff.size(), MPI_UNSIGNED_CHAR, to_proc, |
|---|
| 457 |             MB_MESG_REMOTE_HANDLES_VECTOR, procConfig.proc_comm(), |
|---|
| 458 | Â Â Â Â Â Â Â Â Â Â Â Â &recv_req); |
|---|
| 459 |   if (success != MPI_SUCCESS) return MB_FAILURE; |
|---|
| 460 | Â } |
|---|
| 461 |  else if (store_remote_handles && !iface_layer) { |
|---|
| 462 | Â Â recv_buff.resize(2*num_subranges(final_ents)*sizeof(MBEntityHandle)Â +Â sizeof(int)); |
|---|
| 463 | Â Â |
|---|
| 464 |   success = MPI_Irecv(&recv_buff[0], recv_buff.size(), MPI_UNSIGNED_CHAR, to_proc, |
|---|
| 465 |             MB_MESG_REMOTE_HANDLES_RANGE, procConfig.proc_comm(), |
|---|
| 466 | Â Â Â Â Â Â Â Â Â Â Â Â &recv_req); |
|---|
| 467 |   if (success != MPI_SUCCESS) return MB_FAILURE; |
|---|
| 468 | Â } |
|---|
| 469 | |
|---|
| 470 | Â Â // if the message is large, send a first message to tell how large |
|---|
| 471 |  if (INITIAL_BUFF_SIZE < buff_size) { |
|---|
| 472 |   int tmp_buff_size = -buff_size; |
|---|
| 473 |   int success = MPI_Send(&tmp_buff_size, sizeof(int), MPI_UNSIGNED_CHAR, |
|---|
| 474 |               to_proc, MB_MESG_SIZE, procConfig.proc_comm()); |
|---|
| 475 |   if (success != MPI_SUCCESS) return MB_FAILURE; |
|---|
| 476 | Â } |
|---|
| 477 | Â Â |
|---|
| 478 | Â Â // send the buffer |
|---|
| 479 |  success = MPI_Isend(&send_buff[0], buff_size, MPI_UNSIGNED_CHAR, to_proc, |
|---|
| 480 |            MB_MESG_ENTS, procConfig.proc_comm(), &send_req); |
|---|
| 481 |  if (success != MPI_SUCCESS) return MB_FAILURE; |
|---|
| 482 | |
|---|
| 483 |  return result; |
|---|
| 484 | #endif |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | MBErrorCode MBParallelComm::recv_size_buff(const int from_proc, |
|---|
| 488 |                       std::vector<unsigned char> &recv_buff, |
|---|
| 489 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MPI_Request &recv_req, |
|---|
| 490 |                       int mesg_tag) |
|---|
| 491 | { |
|---|
| 492 | Â Â // use the received size to resize buffer, then post another irecv |
|---|
| 493 | Â recv_buff.resize(-(*((int*)&recv_buff[0]))); |
|---|
| 494 |  int success = MPI_Irecv(&recv_buff[0], recv_buff.size(), MPI_UNSIGNED_CHAR, from_proc, |
|---|
| 495 |              mesg_tag, procConfig.proc_comm(), &recv_req); |
|---|
| 496 |  if (MPI_SUCCESS != success) { |
|---|
| 497 | Â Â MBErrorCode result =Â MB_FAILURE; |
|---|
| 498 | Â Â RRA("Failed call to Irecv in recv_size_buff."); |
|---|
| 499 | Â } |
|---|
| 500 | Â |
|---|
| 501 |  return MB_SUCCESS; |
|---|
| 502 | } |
|---|
| 503 | Â |
|---|
| 504 | MBErrorCode MBParallelComm::recv_unpack_entities(const int from_proc, |
|---|
| 505 |                          const bool store_remote_handles, |
|---|
| 506 |                          const bool iface_layer, |
|---|
| 507 |                          std::vector<unsigned char> &recv_buff, |
|---|
| 508 |                          std::vector<unsigned char> &send_buff, |
|---|
| 509 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MPI_Request &send_req, |
|---|
| 510 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &recd_ents) |
|---|
| 511 | { |
|---|
| 512 | #ifndef USE_MPI |
|---|
| 513 |  return MB_FAILURE; |
|---|
| 514 | #else |
|---|
| 515 | |
|---|
| 516 | Â MBErrorCode result =Â MB_SUCCESS; |
|---|
| 517 | Â |
|---|
| 518 | Â Â // unpack the buffer |
|---|
| 519 |  if (iface_layer) { |
|---|
| 520 | Â Â std::vector<MBEntityHandle>Â recd_ents_tmp; |
|---|
| 521 |   unsigned char *buff_ptr = &recv_buff[0]; |
|---|
| 522 |   result = unpack_iface_entities(buff_ptr, from_proc, recd_ents_tmp); |
|---|
| 523 | Â Â RRA("Failed to unpack buffer in recv_unpack."); |
|---|
| 524 |   if (store_remote_handles) { |
|---|
| 525 |    int recd_size = recd_ents_tmp.size()*sizeof(MBEntityHandle) + |
|---|
| 526 | Â Â Â Â Â sizeof(int); |
|---|
| 527 | Â Â Â send_buff.resize(recd_size); |
|---|
| 528 |    unsigned char *buff_ptr = &send_buff[0]; |
|---|
| 529 |    PACK_INT(buff_ptr, recd_ents_tmp.size()); |
|---|
| 530 |    PACK_EH(buff_ptr, &recd_ents_tmp[0], recd_ents_tmp.size()); |
|---|
| 531 |    int success = MPI_Isend(&send_buff[0], recd_size, MPI_UNSIGNED_CHAR, from_proc, |
|---|
| 532 |                MB_MESG_REMOTE_HANDLES_VECTOR, procConfig.proc_comm(), &send_req); |
|---|
| 533 |    if (success != MPI_SUCCESS) { |
|---|
| 534 | Â Â Â Â result =Â MB_FAILURE; |
|---|
| 535 | Â Â Â Â RRA("Failed to send handles in recv_unpack."); |
|---|
| 536 | Â Â Â } |
|---|
| 537 | Â Â } |
|---|
| 538 |   std::copy(recd_ents_tmp.begin(), recd_ents_tmp.end(), mb_range_inserter(recd_ents)); |
|---|
| 539 | Â } |
|---|
| 540 |  else { |
|---|
| 541 |   result = unpack_buffer(&recv_buff[0], store_remote_handles, from_proc, recd_ents); |
|---|
| 542 | Â Â RRA("Failed to unpack buffer in recv_unpack."); |
|---|
| 543 |   if (store_remote_handles) { |
|---|
| 544 |    int recd_size = 2*num_subranges(recd_ents)*sizeof(MBEntityHandle) + sizeof(int); |
|---|
| 545 | Â Â Â send_buff.resize(recd_size); |
|---|
| 546 |    unsigned char *buff_ptr = &send_buff[0]; |
|---|
| 547 |    PACK_RANGE(buff_ptr, recd_ents); |
|---|
| 548 |    int success = MPI_Isend(&send_buff[0], recd_size, MPI_UNSIGNED_CHAR, from_proc, |
|---|
| 549 |              MB_MESG_REMOTE_HANDLES_RANGE, procConfig.proc_comm(), &send_req); |
|---|
| 550 |    if (success != MPI_SUCCESS) { |
|---|
| 551 | Â Â Â Â result =Â MB_FAILURE; |
|---|
| 552 | Â Â Â Â RRA("Failed to send handles in recv_unpack."); |
|---|
| 553 | Â Â Â } |
|---|
| 554 | Â Â } |
|---|
| 555 | Â } |
|---|
| 556 | |
|---|
| 557 |  return result; |
|---|
| 558 | #endif |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | MBErrorCode MBParallelComm::broadcast_entities( const int from_proc, |
|---|
| 562 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &entities, |
|---|
| 563 |                         const bool adjacencies, |
|---|
| 564 |                         const bool tags) |
|---|
| 565 | { |
|---|
| 566 | #ifndef USE_MPI |
|---|
| 567 |  return MB_FAILURE; |
|---|
| 568 | #else |
|---|
| 569 | Â |
|---|
| 570 | Â MBErrorCode result =Â MB_SUCCESS; |
|---|
| 571 |  int success; |
|---|
| 572 | Â MBRange whole_range; |
|---|
| 573 |  int buff_size; |
|---|
| 574 | Â |
|---|
| 575 |  std::vector<unsigned char> buff; |
|---|
| 576 |  if ((int)procConfig.proc_rank() == from_proc) { |
|---|
| 577 |   result = pack_buffer( entities, adjacencies, tags, |
|---|
| 578 |              false, false, -1, |
|---|
| 579 |              whole_range, buff, buff_size); |
|---|
| 580 | Â Â RRA("Failed to compute buffer size in broadcast_entities."); |
|---|
| 581 | Â } |
|---|
| 582 | |
|---|
| 583 |  success = MPI_Bcast( &buff_size, 1, MPI_INT, from_proc, procConfig.proc_comm() ); |
|---|
| 584 |  if (MPI_SUCCESS != success) { |
|---|
| 585 | Â Â result =Â MB_FAILURE; |
|---|
| 586 | Â Â RRA("MPI_Bcast of buffer size failed."); |
|---|
| 587 | Â } |
|---|
| 588 | Â |
|---|
| 589 |  if (!buff_size) // no data |
|---|
| 590 |   return MB_SUCCESS; |
|---|
| 591 | |
|---|
| 592 |  if ((int)procConfig.proc_rank() != from_proc) |
|---|
| 593 | Â Â buff.resize(buff_size); |
|---|
| 594 | |
|---|
| 595 | Â size_t offset =Â 0; |
|---|
| 596 |  while (buff_size) { |
|---|
| 597 |   int size = std::min( buff_size, MAX_BCAST_SIZE ); |
|---|
| 598 |   success = MPI_Bcast( &buff[offset], size, MPI_UNSIGNED_CHAR, from_proc, procConfig.proc_comm() ); |
|---|
| 599 |   if (MPI_SUCCESS != success) { |
|---|
| 600 | Â Â Â result =Â MB_FAILURE; |
|---|
| 601 | Â Â Â RRA("MPI_Bcast of buffer failed."); |
|---|
| 602 | Â Â } |
|---|
| 603 | Â Â |
|---|
| 604 | Â Â offset +=Â size; |
|---|
| 605 | Â Â buff_size -=Â size; |
|---|
| 606 | Â } |
|---|
| 607 | |
|---|
| 608 |  if ((int)procConfig.proc_rank() != from_proc) { |
|---|
| 609 |   result = unpack_buffer(&buff[0], false, from_proc, entities); |
|---|
| 610 | Â Â RRA("Failed to unpack buffer in broadcast_entities."); |
|---|
| 611 | Â } |
|---|
| 612 | |
|---|
| 613 |  return MB_SUCCESS; |
|---|
| 614 | #endif |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | MBErrorCode MBParallelComm::pack_buffer(MBRange &orig_ents, |
|---|
| 618 |                     const bool adjacencies, |
|---|
| 619 |                     const bool tags, |
|---|
| 620 |                     const bool store_remote_handles, |
|---|
| 621 |                     const bool iface_layer, |
|---|
| 622 |                     const int to_proc, |
|---|
| 623 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &final_ents, |
|---|
| 624 |                     std::vector<unsigned char> &buff, |
|---|
| 625 |                     int &buff_size) |
|---|
| 626 | { |
|---|
| 627 | Â Â // pack the buffer with the entity ranges, adjacencies, and tags sections |
|---|
| 628 | Â Â // |
|---|
| 629 | Â Â // Note: new entities used in subsequent connectivity lists, sets, or tags, |
|---|
| 630 | Â Â //Â Â are referred to as (MBMAXTYPE + index), where index is into vector |
|---|
| 631 | Â Â //Â Â of new entities, 0-based |
|---|
| 632 | Â Â // |
|---|
| 633 | Â Â // DATA LAYOUT IN BUFFER: |
|---|
| 634 | Â Â // . w/ handles ? (0-no, 1-yes, range, 2-yes, vector) |
|---|
| 635 | Â Â // ENTITIES: |
|---|
| 636 | Â Â // . for all types: |
|---|
| 637 | Â Â //Â Â - ent_type -- end of data indicated by ent_type == MBMAXTYPE |
|---|
| 638 | Â Â //Â Â - range(ent type) -- #ents = range.size() |
|---|
| 639 | Â Â //Â Â - if (ent_type == MBVERTEX) xxx[#ents], yyy[#ents], zzz[#ents] |
|---|
| 640 | Â Â //Â Â - else { |
|---|
| 641 | Â Â //Â Â Â . nodes_per_ent |
|---|
| 642 | Â Â //Â Â Â . connect[#ents * nodes_per_ent] |
|---|
| 643 | Â Â //Â Â - } |
|---|
| 644 | Â Â //Â Â - if (handles) range/vector of remote handles |
|---|
| 645 | Â Â // SETS: |
|---|
| 646 | Â Â // . range of set handles -- (#sets = range.size()) |
|---|
| 647 | Â Â // . options[#sets] (unsigned int) |
|---|
| 648 | Â Â // . if (unordered) set range |
|---|
| 649 | Â Â // . else if ordered |
|---|
| 650 | Â Â //Â Â - #ents in set |
|---|
| 651 | Â Â //Â Â - handles[#ents] |
|---|
| 652 | Â Â // . #parents |
|---|
| 653 | Â Â // . if (#parents) handles[#parents] |
|---|
| 654 | Â Â // . #children |
|---|
| 655 | Â Â // . if (#children) handles[#children] |
|---|
| 656 | Â Â // ADJACENCIES: |
|---|
| 657 | Â Â // (no adjs for now) |
|---|
| 658 | Â Â // TAGS: |
|---|
| 659 | Â Â // . #tags |
|---|
| 660 | Â Â // . for each tag |
|---|
| 661 | Â Â //Â Â - tag size |
|---|
| 662 | Â Â //Â Â - tag type |
|---|
| 663 | Â Â //Â Â - data type |
|---|
| 664 | Â Â //Â Â - if (default value) |
|---|
| 665 | Â Â //Â Â Â . 1 |
|---|
| 666 | Â Â //Â Â Â . default value |
|---|
| 667 | Â Â //Â Â - else |
|---|
| 668 | Â Â //Â Â Â . 0 |
|---|
| 669 | Â Â //Â Â - name (null-terminated string, in char[64]) |
|---|
| 670 | Â Â //Â Â - range (size = #ents) |
|---|
| 671 | Â Â //Â Â - tag_vals[#ents] |
|---|
| 672 | |
|---|
| 673 | Â MBErrorCode result; |
|---|
| 674 | |
|---|
| 675 | Â std::vector<MBEntityType>Â ent_types; |
|---|
| 676 | Â std::vector<MBRange>Â all_ranges; |
|---|
| 677 | Â std::vector<int>Â verts_per_entity; |
|---|
| 678 | Â MBRange set_range; |
|---|
| 679 | Â std::vector<MBRange>Â set_ranges; |
|---|
| 680 | Â std::vector<MBTag>Â all_tags; |
|---|
| 681 | Â std::vector<MBRange>Â tag_ranges; |
|---|
| 682 | Â std::vector<int>Â set_sizes; |
|---|
| 683 |  std::vector<unsigned int> options_vec; |
|---|
| 684 | |
|---|
| 685 | Â buff_size =Â 0; |
|---|
| 686 | Â MBRange::const_iterator rit; |
|---|
| 687 | Â |
|---|
| 688 | Â Â //================= |
|---|
| 689 | Â Â // count first... |
|---|
| 690 | Â Â //================= |
|---|
| 691 | |
|---|
| 692 |  unsigned char *buff_ptr = NULL; |
|---|
| 693 | Â |
|---|
| 694 | Â Â // entities |
|---|
| 695 |  result = pack_entities(orig_ents, rit, final_ents, buff_ptr, |
|---|
| 696 |              buff_size, true, store_remote_handles, |
|---|
| 697 |              iface_layer, to_proc, ent_types, all_ranges, |
|---|
| 698 | Â Â Â Â Â Â Â Â Â Â Â Â Â verts_per_entity);Â |
|---|
| 699 | Â RRA("Packing entities (count) failed."); |
|---|
| 700 | Â |
|---|
| 701 | Â Â // sets |
|---|
| 702 |  result = pack_sets(orig_ents, rit, final_ents, buff_ptr, buff_size, true, |
|---|
| 703 |            store_remote_handles, to_proc, set_range, set_ranges, |
|---|
| 704 |            set_sizes, options_vec); |
|---|
| 705 | Â RRA("Packing sets (count) failed."); |
|---|
| 706 | Â |
|---|
| 707 | Â Â // adjacencies |
|---|
| 708 |  if (adjacencies) { |
|---|
| 709 |   result = pack_adjacencies(orig_ents, rit, final_ents, buff_ptr, |
|---|
| 710 |                buff_size, true, |
|---|
| 711 |                store_remote_handles, to_proc); |
|---|
| 712 | Â Â RRA("Packing adjs (count) failed."); |
|---|
| 713 | Â } |
|---|
| 714 | Â Â |
|---|
| 715 | Â Â // tags |
|---|
| 716 |  if (tags) { |
|---|
| 717 |   result = get_tag_send_list( final_ents, all_tags, tag_ranges ); |
|---|
| 718 | Â Â RRA("Failed to get tagged entities.") |
|---|
| 719 |   result = pack_tags(orig_ents, rit, final_ents, buff_ptr, |
|---|
| 720 |             buff_size, true, store_remote_handles, to_proc, |
|---|
| 721 |             all_tags, tag_ranges); |
|---|
| 722 | Â Â RRA("Packing tags (count) failed."); |
|---|
| 723 | Â } |
|---|
| 724 | |
|---|
| 725 | Â Â //================= |
|---|
| 726 | Â Â // now do the real packing |
|---|
| 727 | Â Â //================= |
|---|
| 728 | |
|---|
| 729 | Â assert(0Â <=Â buff_size); |
|---|
| 730 | Â buff.resize(buff_size); |
|---|
| 731 |  int orig_buff_size = buff_size; |
|---|
| 732 | Â buff_size =Â 0; |
|---|
| 733 | Â buff_ptr =Â &buff[0]; |
|---|
| 734 | Â |
|---|
| 735 | Â Â // entities |
|---|
| 736 |  result = pack_entities(orig_ents, rit, final_ents, buff_ptr, |
|---|
| 737 |              buff_size, false, store_remote_handles, |
|---|
| 738 |              iface_layer, to_proc, ent_types, |
|---|
| 739 |              all_ranges, verts_per_entity); |
|---|
| 740 | Â RRA("Packing entities (real) failed."); |
|---|
| 741 | #ifdef DEBUG_PACKING |
|---|
| 742 | Â std::cerr <<Â "pack_entities buffer space: "Â <<Â buff_ptr -Â &buff[0]Â <<Â " bytes."Â <<Â std::endl; |
|---|
| 743 |  unsigned char *tmp_buff = buff_ptr; |
|---|
| 744 | #endif |
|---|
| 745 | Â |
|---|
| 746 | Â Â // sets |
|---|
| 747 |  result = pack_sets(orig_ents, rit, final_ents, buff_ptr, buff_size, false, |
|---|
| 748 |            store_remote_handles, to_proc, set_range, set_ranges, |
|---|
| 749 |            set_sizes, options_vec); |
|---|
| 750 | Â RRA("Packing sets (real) failed."); |
|---|
| 751 | #ifdef DEBUG_PACKING |
|---|
| 752 | Â std::cerr <<Â "pack_sets buffer space: "Â <<Â buff_ptr -Â tmp_buff <<Â " bytes."Â <<Â std::endl; |
|---|
| 753 | Â tmp_buff =Â buff_ptr; |
|---|
| 754 | #endif |
|---|
| 755 | Â |
|---|
| 756 | Â Â // adjacencies |
|---|
| 757 |  if (adjacencies) { |
|---|
| 758 |   result = pack_adjacencies(orig_ents, rit, final_ents, buff_ptr, |
|---|
| 759 |                buff_size, false, |
|---|
| 760 |                store_remote_handles, to_proc); |
|---|
| 761 | Â Â RRA("Packing adjs (real) failed."); |
|---|
| 762 | Â } |
|---|
| 763 | Â Â |
|---|
| 764 | Â Â // tags |
|---|
| 765 |  if (tags) { |
|---|
| 766 |   result = pack_tags(orig_ents, rit, final_ents, buff_ptr, |
|---|
| 767 |             buff_size, false, store_remote_handles, to_proc, all_tags, |
|---|
| 768 | Â Â Â Â Â Â Â Â Â Â Â Â tag_ranges); |
|---|
| 769 | Â Â RRA("Packing tags (real) failed."); |
|---|
| 770 | #ifdef DEBUG_PACKING |
|---|
| 771 | Â Â std::cerr <<Â "pack_tags buffer space: "Â <<Â buff_ptr -Â tmp_buff <<Â " bytes."Â <<Â std::endl; |
|---|
| 772 | Â Â tmp_buff =Â buff_ptr; |
|---|
| 773 | #endif |
|---|
| 774 | Â } |
|---|
| 775 | |
|---|
| 776 | Â Â // original buffer size might be larger, because some |
|---|
| 777 | Â Â // ranges of local handles pack into more compact ranges of |
|---|
| 778 | Â Â // remote handles (because they're expressed using MBMAXTYPE plus |
|---|
| 779 | Â Â // index in new entity range, and that list of entities is likely |
|---|
| 780 | Â Â // to be compact) |
|---|
| 781 | Â assert(orig_buff_size >=Â buff_size); |
|---|
| 782 | |
|---|
| 783 |  return result; |
|---|
| 784 | } |
|---|
| 785 | Â |
|---|
| 786 | MBErrorCode MBParallelComm::unpack_buffer(unsigned char *buff_ptr, |
|---|
| 787 |                      const bool store_remote_handles, |
|---|
| 788 |                      int from_proc, |
|---|
| 789 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &final_ents) |
|---|
| 790 | { |
|---|
| 791 |  if (myBuffer.capacity() == 0) return MB_FAILURE; |
|---|
| 792 | Â |
|---|
| 793 | #ifdef DEBUG_PACKING |
|---|
| 794 |   unsigned char *tmp_buff = buff_ptr; |
|---|
| 795 | #endif |
|---|
| 796 |  MBErrorCode result = unpack_entities(buff_ptr, store_remote_handles, |
|---|
| 797 |                     from_proc, final_ents); |
|---|
| 798 | Â RRA("Unpacking entities failed."); |
|---|
| 799 | #ifdef DEBUG_PACKING |
|---|
| 800 | Â Â std::cerr <<Â "unpack_entities buffer space: "Â <<Â buff_ptr -Â tmp_buff <<Â " bytes."Â <<Â std::endl; |
|---|
| 801 | Â Â tmp_buff =Â buff_ptr; |
|---|
| 802 | #endif |
|---|
| 803 |  result = unpack_sets(buff_ptr, final_ents, store_remote_handles, |
|---|
| 804 | Â Â Â Â Â Â Â Â Â Â Â Â from_proc); |
|---|
| 805 | Â RRA("Unpacking sets failed."); |
|---|
| 806 | #ifdef DEBUG_PACKING |
|---|
| 807 | Â Â std::cerr <<Â "unpack_sets buffer space: "Â <<Â buff_ptr -Â tmp_buff <<Â " bytes."Â <<Â std::endl; |
|---|
| 808 | Â Â tmp_buff =Â buff_ptr; |
|---|
| 809 | #endif |
|---|
| 810 |  result = unpack_tags(buff_ptr, final_ents, store_remote_handles, |
|---|
| 811 | Â Â Â Â Â Â Â Â Â Â Â Â from_proc); |
|---|
| 812 | Â RRA("Unpacking tags failed."); |
|---|
| 813 | #ifdef DEBUG_PACKING |
|---|
| 814 | Â Â std::cerr <<Â "unpack_tags buffer space: "Â <<Â buff_ptr -Â tmp_buff <<Â " bytes."Â <<Â std::endl; |
|---|
| 815 | Â Â tmp_buff =Â buff_ptr; |
|---|
| 816 | #endif |
|---|
| 817 | |
|---|
| 818 | #ifdef DEBUG_PACKING |
|---|
| 819 | Â std::cerr <<Â std::endl; |
|---|
| 820 | #endif |
|---|
| 821 | Â |
|---|
| 822 |  return MB_SUCCESS; |
|---|
| 823 | } |
|---|
| 824 | |
|---|
| 825 | int MBParallelComm::num_subranges(const MBRange &this_range) |
|---|
| 826 | { |
|---|
| 827 | Â Â // ok, have all the ranges we'll pack; count the subranges |
|---|
| 828 |  int num_sub_ranges = 0; |
|---|
| 829 |  for (MBRange::const_pair_iterator pit = this_range.const_pair_begin(); |
|---|
| 830 | Â Â Â Â pit !=Â this_range.const_pair_end();Â pit++) |
|---|
| 831 | Â Â num_sub_ranges++; |
|---|
| 832 | |
|---|
| 833 |  return num_sub_ranges; |
|---|
| 834 | } |
|---|
| 835 | |
|---|
| 836 | MBErrorCode MBParallelComm::pack_entities(MBRange &entities, |
|---|
| 837 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange::const_iterator &start_rit, |
|---|
| 838 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &whole_range, |
|---|
| 839 |                      unsigned char *&buff_ptr, |
|---|
| 840 |                      int &count, |
|---|
| 841 |                      const bool just_count, |
|---|
| 842 |                      const bool store_remote_handles, |
|---|
| 843 |                      const bool iface_layer, |
|---|
| 844 |                      const int to_proc, |
|---|
| 845 |                      std::vector<MBEntityType> &ent_types, |
|---|
| 846 |                      std::vector<MBRange> &all_ranges, |
|---|
| 847 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â std::vector<int>Â &verts_per_entity)Â |
|---|
| 848 | { |
|---|
| 849 | Â Â // (. w/ handles ? (0-no, 1-yes, range, 2-yes, vector)) |
|---|
| 850 | Â Â // ENTITIES: |
|---|
| 851 | Â Â // . for all types: |
|---|
| 852 | Â Â //Â Â - ent_type -- end of data indicated by ent_type == MBMAXTYPE |
|---|
| 853 | Â Â //Â Â - #ents |
|---|
| 854 | Â Â //Â Â - if (ent_type == MBVERTEX) xxx[#ents], yyy[#ents], zzz[#ents] |
|---|
| 855 | Â Â //Â Â - else { |
|---|
| 856 | Â Â //Â Â Â . nodes_per_ent |
|---|
| 857 | Â Â //Â Â Â . connect[#ents * nodes_per_ent] |
|---|
| 858 | Â Â //Â Â - } |
|---|
| 859 | Â Â //Â Â - if (handles) range/vector of remote handles |
|---|
| 860 | |
|---|
| 861 |  unsigned char *orig_buff_ptr = buff_ptr; |
|---|
| 862 | Â MBErrorCode result; |
|---|
| 863 | Â MBWriteUtilIface *wu =Â NULL; |
|---|
| 864 |  if (!just_count) { |
|---|
| 865 |   result = mbImpl->query_interface(std::string("MBWriteUtilIface"), |
|---|
| 866 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â reinterpret_cast<void**>(&wu)); |
|---|
| 867 | Â Â RRA("Couldn't get MBWriteUtilIface."); |
|---|
| 868 | |
|---|
| 869 | Â } |
|---|
| 870 | Â |
|---|
| 871 | Â Â // pack vertices |
|---|
| 872 |  if (just_count) { |
|---|
| 873 | Â Â Â // don't count size of verts until after all entities are included |
|---|
| 874 | Â Â ent_types.push_back(MBVERTEX); |
|---|
| 875 | Â Â verts_per_entity.push_back(1); |
|---|
| 876 | Â Â all_ranges.push_back(entities.subset_by_type(MBVERTEX)); |
|---|
| 877 | Â } |
|---|
| 878 |  else { |
|---|
| 879 |   if (!all_ranges[0].empty()) { |
|---|
| 880 |    PACK_INT(buff_ptr, ((int) MBVERTEX)); |
|---|
| 881 |    PACK_INT(buff_ptr, ((int) all_ranges[0].size())); |
|---|
| 882 |    int num_verts = all_ranges[0].size(); |
|---|
| 883 | Â Â Â std::vector<double*>Â coords(3); |
|---|
| 884 |    for (int i = 0; i < 3; i++) |
|---|
| 885 | Â Â Â Â coords[i]Â =Â reinterpret_cast<double*>(buff_ptr +Â i *Â num_verts *Â sizeof(double)); |
|---|
| 886 | |
|---|
| 887 | Â Â Â assert(NULLÂ !=Â wu); |
|---|
| 888 | Â Â |
|---|
| 889 |    result = wu->get_node_arrays(3, num_verts, all_ranges[0], 0, 0, coords); |
|---|
| 890 | Â Â Â RRA("Couldn't allocate node space."); |
|---|
| 891 |    PC(3*num_verts, " doubles"); |
|---|
| 892 | |
|---|
| 893 | Â Â Â buff_ptr +=Â 3Â *Â num_verts *Â sizeof(double); |
|---|
| 894 | |
|---|
| 895 |    if (store_remote_handles) |
|---|
| 896 |     PACK_RANGE(buff_ptr, all_ranges[0]); |
|---|
| 897 | |
|---|
| 898 | #ifdef DEBUG_PACKING |
|---|
| 899 | Â Â Â std::cerr <<Â "Packed "Â <<Â all_ranges[0].size()Â <<Â " vertices."Â <<Â std::endl; |
|---|
| 900 | #endif   |
|---|
| 901 | Â Â } |
|---|
| 902 | Â } |
|---|
| 903 | |
|---|
| 904 | Â Â // place an iterator at the first non-vertex entity |
|---|
| 905 |  if (!all_ranges[0].empty()) { |
|---|
| 906 | Â Â start_rit =Â entities.find(*all_ranges[0].rbegin()); |
|---|
| 907 | Â Â start_rit++; |
|---|
| 908 | Â } |
|---|
| 909 |  else { |
|---|
| 910 | Â Â start_rit =Â entities.begin(); |
|---|
| 911 | Â } |
|---|
| 912 | Â |
|---|
| 913 | Â MBRange::const_iterator end_rit =Â start_rit; |
|---|
| 914 | Â std::vector<MBRange>::iterator allr_it =Â all_ranges.begin(); |
|---|
| 915 | Â |
|---|
| 916 | Â Â // pack entities |
|---|
| 917 |  if (just_count) {  |
|---|
| 918 | |
|---|
| 919 | Â Â Â // get all ranges of entities that have different #'s of vertices or different types |
|---|
| 920 |   while (end_rit != entities.end() && TYPE_FROM_HANDLE(*start_rit) != MBENTITYSET) { |
|---|
| 921 | |
|---|
| 922 | Â Â Â Â // get the sequence holding this entity |
|---|
| 923 | Â Â Â EntitySequence *seq; |
|---|
| 924 | Â Â Â ElementSequence *eseq; |
|---|
| 925 |    result = sequenceManager->find(*start_rit, seq); |
|---|
| 926 | Â Â Â RRA("Couldn't find entity sequence."); |
|---|
| 927 | |
|---|
| 928 |    if (NULL == seq) return MB_FAILURE; |
|---|
| 929 | Â Â Â eseq =Â dynamic_cast<ElementSequence*>(seq); |
|---|
| 930 | |
|---|
| 931 | Â Â Â Â // if type and nodes per element change, start a new range |
|---|
| 932 |    if (eseq->type() != *ent_types.rbegin() || |
|---|
| 933 | Â Â Â Â Â (int)Â eseq->nodes_per_element()Â !=Â *verts_per_entity.rbegin())Â { |
|---|
| 934 | Â Â Â Â ent_types.push_back(eseq->type()); |
|---|
| 935 | Â Â Â Â verts_per_entity.push_back(eseq->nodes_per_element()); |
|---|
| 936 | Â Â Â Â all_ranges.push_back(MBRange()); |
|---|
| 937 | Â Â Â Â allr_it++; |
|---|
| 938 | Â Â Â } |
|---|
| 939 | Â Â |
|---|
| 940 | Â Â Â Â // get position in entities list one past end of this sequence |
|---|
| 941 |    end_rit = entities.lower_bound(start_rit, entities.end(), eseq->end_handle()+1); |
|---|
| 942 | |
|---|
| 943 | Â Â Â Â // put these entities in the last range |
|---|
| 944 |    std::copy(start_rit, end_rit, mb_range_inserter(*all_ranges.rbegin())); |
|---|
| 945 | |
|---|
| 946 | Â Â Â Â // remove any which are already shared |
|---|
| 947 |    if (store_remote_handles && !iface_layer) { |
|---|
| 948 |     result = remove_nonowned_shared(*all_ranges.rbegin(), to_proc, false); |
|---|
| 949 | Â Â Â Â RRA("Failed nonowned_shared test."); |
|---|
| 950 | Â Â Â } |
|---|
| 951 | |
|---|
| 952 | Â Â Â whole_range.merge(*all_ranges.rbegin()); |
|---|
| 953 | Â Â Â |
|---|
| 954 | Â Â Â Â // now start where we last left off |
|---|
| 955 | Â Â Â start_rit =Â end_rit; |
|---|
| 956 | Â Â } |
|---|
| 957 | |
|---|
| 958 | Â Â Â // update vertex range to cover vertices included in other entities |
|---|
| 959 | Â Â Â // and remove entities already there |
|---|
| 960 |   result = mbImpl->get_adjacencies(whole_range, 0, false, all_ranges[0], |
|---|
| 961 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBInterface::UNION); |
|---|
| 962 | Â Â RRA("Failed get_adjacencies."); |
|---|
| 963 | |
|---|
| 964 |   if (store_remote_handles) { |
|---|
| 965 | Â Â Â whole_range =Â whole_range.subtract(all_ranges[0]); |
|---|
| 966 |    result = remove_nonowned_shared(all_ranges[0], to_proc, false); |
|---|
| 967 | Â Â Â RRA("Failed nonowned_shared test."); |
|---|
| 968 | Â Â } |
|---|
| 969 | Â Â |
|---|
| 970 | Â Â Â // count those data, now that we know which |
|---|
| 971 | Â Â Â // entities get communicated |
|---|
| 972 | Â Â whole_range.merge(all_ranges[0]); |
|---|
| 973 | Â Â count +=Â 3Â *Â sizeof(double)Â *Â all_ranges[0].size(); |
|---|
| 974 | Â Â |
|---|
| 975 | Â Â Â // space for the ranges |
|---|
| 976 | Â Â std::vector<MBRange>::iterator vit =Â all_ranges.begin(); |
|---|
| 977 | Â Â std::vector<int>::iterator iit =Â verts_per_entity.begin(); |
|---|
| 978 | Â Â std::vector<MBEntityType>::iterator eit =Â ent_types.begin(); |
|---|
| 979 |   for (; vit != all_ranges.end(); vit++, iit++, eit++) { |
|---|
| 980 | Â Â Â Â // entity type of this range, but passed as int |
|---|
| 981 | Â Â Â count +=Â sizeof(int); |
|---|
| 982 | Â Â Â |
|---|
| 983 | Â Â Â Â // number of entities |
|---|
| 984 | Â Â Â count +=Â sizeof(int); |
|---|
| 985 | |
|---|
| 986 | Â Â Â Â // nodes per entity |
|---|
| 987 |    if (iit != verts_per_entity.begin()) count += sizeof(int); |
|---|
| 988 | |
|---|
| 989 | Â Â Â Â // connectivity of subrange |
|---|
| 990 |    if (iit != verts_per_entity.begin()) { |
|---|
| 991 | Â Â Â Â count +=Â *iit *Â sizeof(MBEntityHandle)*(*vit).size(); |
|---|
| 992 | Â Â Â } |
|---|
| 993 | Â Â Â |
|---|
| 994 | Â Â Â Â // remote handles, if desired |
|---|
| 995 |    if (store_remote_handles) |
|---|
| 996 | Â Â Â Â count +=Â sizeof(int)Â +Â 2*sizeof(MBEntityHandle)*num_subranges(*vit); |
|---|
| 997 | Â Â } |
|---|
| 998 | |
|---|
| 999 | Â Â Â // extra entity type at end, passed as int |
|---|
| 1000 | Â Â count +=Â sizeof(int); |
|---|
| 1001 | Â } |
|---|
| 1002 |  else { |
|---|
| 1003 | Â Â Â // for each range beyond the first |
|---|
| 1004 | Â Â allr_it++; |
|---|
| 1005 | Â Â std::vector<int>::iterator nv_it =Â verts_per_entity.begin(); |
|---|
| 1006 | Â Â std::vector<MBEntityType>::iterator et_it =Â ent_types.begin(); |
|---|
| 1007 | Â Â std::vector<MBEntityHandle>Â dum_connect; |
|---|
| 1008 | Â Â nv_it++;Â et_it++; |
|---|
| 1009 | Â Â |
|---|
| 1010 |   for (; allr_it != all_ranges.end(); allr_it++, nv_it++, et_it++) { |
|---|
| 1011 | Â Â Â Â // pack the entity type |
|---|
| 1012 |    PACK_INT(buff_ptr, ((int)*et_it)); |
|---|
| 1013 | |
|---|
| 1014 | Â Â Â Â // pack # ents |
|---|
| 1015 |    PACK_INT(buff_ptr, (*allr_it).size()); |
|---|
| 1016 | Â Â Â |
|---|
| 1017 | Â Â Â Â // pack the nodes per entity |
|---|
| 1018 |    PACK_INT(buff_ptr, *nv_it); |
|---|
| 1019 | Â Â Â |
|---|
| 1020 | Â Â Â Â // pack the connectivity |
|---|
| 1021 |    const MBEntityHandle *connect; |
|---|
| 1022 |    int num_connect; |
|---|
| 1023 | Â Â Â MBEntityHandle *start_vec =Â (MBEntityHandle*)buff_ptr; |
|---|
| 1024 |    for (MBRange::const_iterator rit = allr_it->begin(); rit != allr_it->end(); rit++) { |
|---|
| 1025 |     result = mbImpl->get_connectivity(*rit, connect, num_connect, false, |
|---|
| 1026 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &dum_connect); |
|---|
| 1027 | Â Â Â Â RRA("Failed to get connectivity."); |
|---|
| 1028 | Â Â Â Â assert(num_connect ==Â *nv_it); |
|---|
| 1029 |     PACK_EH(buff_ptr, &connect[0], num_connect); |
|---|
| 1030 | Â Â Â } |
|---|
| 1031 | |
|---|
| 1032 | Â Â Â Â // substitute destination handles |
|---|
| 1033 |    result = get_remote_handles(store_remote_handles, start_vec, start_vec, |
|---|
| 1034 |                  *nv_it*(*allr_it).size(), to_proc, |
|---|
| 1035 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â whole_range); |
|---|
| 1036 | Â Â Â RRA("Trouble getting remote handles when packing entities."); |
|---|
| 1037 | |
|---|
| 1038 | Â Â Â Â // pack the handles |
|---|
| 1039 |    if (store_remote_handles) |
|---|
| 1040 |     PACK_RANGE(buff_ptr, (*allr_it)); |
|---|
| 1041 | |
|---|
| 1042 | #ifdef DEBUG_PACKING |
|---|
| 1043 | Â Â Â std::cerr <<Â "Packed "Â <<Â (*allr_it).size()Â <<Â " ents of type "Â |
|---|
| 1044 | Â Â Â Â Â Â Â Â <<Â MBCN::EntityTypeName(TYPE_FROM_HANDLE(*(allr_it->begin())))Â <<Â std::endl; |
|---|
| 1045 | #endif   |
|---|
| 1046 | Â Â Â |
|---|
| 1047 | Â Â } |
|---|
| 1048 | |
|---|
| 1049 | Â Â Â // pack MBMAXTYPE to indicate end of ranges |
|---|
| 1050 |   PACK_INT(buff_ptr, ((int)MBMAXTYPE)); |
|---|
| 1051 | |
|---|
| 1052 | Â Â count +=Â buff_ptr -Â orig_buff_ptr; |
|---|
| 1053 | Â } |
|---|
| 1054 | |
|---|
| 1055 |  if (debug_packing) std::cerr << std::endl << "Done packing entities." << std::endl; |
|---|
| 1056 | |
|---|
| 1057 |  return MB_SUCCESS; |
|---|
| 1058 | } |
|---|
| 1059 | |
|---|
| 1060 | MBErrorCode MBParallelComm::get_remote_handles(const bool store_remote_handles, |
|---|
| 1061 |                         MBEntityHandle *from_vec, |
|---|
| 1062 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBEntityHandle *to_vec_tmp, |
|---|
| 1063 |                         int num_ents, int to_proc, |
|---|
| 1064 |                         const MBRange &new_ents) |
|---|
| 1065 | { |
|---|
| 1066 | Â Â // NOTE: THIS IMPLEMENTATION IS JUST LIKE THE RANGE-BASED VERSION, NO REUSE |
|---|
| 1067 | Â Â // AT THIS TIME, SO IF YOU FIX A BUG IN THIS VERSION, IT MAY BE IN THE |
|---|
| 1068 | Â Â // OTHER VERSION TOO!!! |
|---|
| 1069 |  if (0 == num_ents) return MB_SUCCESS; |
|---|
| 1070 | Â |
|---|
| 1071 | Â Â // use a local destination ptr in case we're doing an in-place copy |
|---|
| 1072 | Â std::vector<MBEntityHandle>Â tmp_vector; |
|---|
| 1073 | Â MBEntityHandle *to_vec =Â to_vec_tmp; |
|---|
| 1074 |  if (to_vec == from_vec) { |
|---|
| 1075 | Â Â tmp_vector.resize(num_ents); |
|---|
| 1076 | Â Â to_vec =Â &tmp_vector[0]; |
|---|
| 1077 | Â } |
|---|
| 1078 | |
|---|
| 1079 |  if (!store_remote_handles) { |
|---|
| 1080 |   int err; |
|---|
| 1081 | Â Â Â // in this case, substitute position in new_ents list |
|---|
| 1082 |   for (int i = 0; i < num_ents; i++) { |
|---|
| 1083 |    int ind = new_ents.index(from_vec[i]); |
|---|
| 1084 |    to_vec[i] = CREATE_HANDLE(MBMAXTYPE, ind, err); |
|---|
| 1085 | Â Â Â assert(to_vec[i]Â !=Â 0Â &&Â !err &&Â -1Â !=Â ind); |
|---|
| 1086 | Â Â } |
|---|
| 1087 | Â } |
|---|
| 1088 |  else { |
|---|
| 1089 |   MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag; |
|---|
| 1090 |   MBErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, |
|---|
| 1091 |                        sharedh_tag, sharedhs_tag, pstatus_tag); |
|---|
| 1092 | Â |
|---|
| 1093 | Â Â Â // get single-proc destination handles and shared procs |
|---|
| 1094 | Â Â std::vector<int>Â sharing_procs(num_ents); |
|---|
| 1095 |   result = mbImpl->tag_get_data(sharedh_tag, from_vec, num_ents, |
|---|
| 1096 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â to_vec); |
|---|
| 1097 | Â Â RRA("Failed to get shared handle tag for remote_handles."); |
|---|
| 1098 |   result = mbImpl->tag_get_data(sharedp_tag, from_vec, num_ents, &sharing_procs[0]); |
|---|
| 1099 | Â Â RRA("Failed to get sharing proc tag in remote_handles."); |
|---|
| 1100 |   for (int j = 0; j < num_ents; j++) { |
|---|
| 1101 |    if (to_vec[j] && sharing_procs[j] != to_proc) |
|---|
| 1102 | Â Â Â Â to_vec[j]Â =Â 0; |
|---|
| 1103 | Â Â } |
|---|
| 1104 | Â Â |
|---|
| 1105 | Â Â MBEntityHandle tmp_handles[MAX_SHARING_PROCS]; |
|---|
| 1106 |   int tmp_procs[MAX_SHARING_PROCS]; |
|---|
| 1107 |   int i; |
|---|
| 1108 | Â Â Â // go through results, and for 0-valued ones, look for multiple shared proc |
|---|
| 1109 | Â Â MBEntityHandle *tmp_eh; |
|---|
| 1110 |   for (tmp_eh = to_vec, i = 0; i < num_ents; i++) { |
|---|
| 1111 |    if (!to_vec[i]) { |
|---|
| 1112 |     result = mbImpl->tag_get_data(sharedps_tag, from_vec+i, 1, tmp_procs); |
|---|
| 1113 |     if (MB_SUCCESS == result) { |
|---|
| 1114 |      for (int j = 0; j < MAX_SHARING_PROCS; j++) { |
|---|
| 1115 |       if (-1 == tmp_procs[j]) break; |
|---|
| 1116 |       else if (tmp_procs[j] == to_proc) { |
|---|
| 1117 |        result = mbImpl->tag_get_data(sharedhs_tag, from_vec+i, 1, tmp_handles); |
|---|
| 1118 | Â Â Â Â Â Â Â RRA("Trouble getting sharedhs tag."); |
|---|
| 1119 | Â Â Â Â Â Â Â to_vec[i]Â =Â tmp_handles[j]; |
|---|
| 1120 | Â Â Â Â Â Â Â assert(to_vec[i]); |
|---|
| 1121 | Â Â Â Â Â Â Â break; |
|---|
| 1122 | Â Â Â Â Â Â } |
|---|
| 1123 | Â Â Â Â Â } |
|---|
| 1124 | Â Â Â Â } |
|---|
| 1125 |     if (!to_vec[i]) { |
|---|
| 1126 |      int j = new_ents.index(from_vec[i]); |
|---|
| 1127 |      if (-1 == j) { |
|---|
| 1128 | Â Â Â Â Â Â result =Â MB_FAILURE; |
|---|
| 1129 | Â Â Â Â Â Â RRA("Failed to find new entity in send list."); |
|---|
| 1130 | Â Â Â Â Â } |
|---|
| 1131 |      int err; |
|---|
| 1132 |      to_vec[i] = CREATE_HANDLE(MBMAXTYPE, j, err); |
|---|
| 1133 |      if (err) { |
|---|
| 1134 | Â Â Â Â Â Â result =Â MB_FAILURE; |
|---|
| 1135 | Â Â Â Â Â Â RRA("Failed to create handle in remote_handles."); |
|---|
| 1136 | Â Â Â Â Â } |
|---|
| 1137 | Â Â Â Â } |
|---|
| 1138 | Â Â Â } |
|---|
| 1139 | Â Â } |
|---|
| 1140 | Â } |
|---|
| 1141 | Â |
|---|
| 1142 | Â Â // memcpy over results if from_vec and to_vec are the same |
|---|
| 1143 |  if (to_vec_tmp == from_vec) |
|---|
| 1144 |   memcpy(from_vec, to_vec, num_ents * sizeof(MBEntityHandle)); |
|---|
| 1145 | Â |
|---|
| 1146 |  return MB_SUCCESS; |
|---|
| 1147 | } |
|---|
| 1148 | |
|---|
| 1149 | MBErrorCode MBParallelComm::get_remote_handles(const bool store_remote_handles, |
|---|
| 1150 |                         const MBRange &from_range, |
|---|
| 1151 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBEntityHandle *to_vec, |
|---|
| 1152 |                         int to_proc, |
|---|
| 1153 |                         const MBRange &new_ents) |
|---|
| 1154 | { |
|---|
| 1155 | Â Â // NOTE: THIS IMPLEMENTATION IS JUST LIKE THE VECTOR-BASED VERSION, NO REUSE |
|---|
| 1156 | Â Â // AT THIS TIME, SO IF YOU FIX A BUG IN THIS VERSION, IT MAY BE IN THE |
|---|
| 1157 | Â Â // OTHER VERSION TOO!!! |
|---|
| 1158 |  if (from_range.empty()) return MB_SUCCESS; |
|---|
| 1159 | Â |
|---|
| 1160 |  if (!store_remote_handles) { |
|---|
| 1161 |   int err; |
|---|
| 1162 | Â Â Â // in this case, substitute position in new_ents list |
|---|
| 1163 | Â Â MBRange::iterator rit; |
|---|
| 1164 |   unsigned int i; |
|---|
| 1165 |   for (rit = from_range.begin(), i = 0; rit != from_range.end(); rit++, i++) { |
|---|
| 1166 |    int ind = new_ents.index(*rit); |
|---|
| 1167 |    to_vec[i] = CREATE_HANDLE(MBMAXTYPE, ind, err); |
|---|
| 1168 | Â Â Â assert(to_vec[i]Â !=Â 0Â &&Â !err &&Â -1Â !=Â ind); |
|---|
| 1169 | Â Â } |
|---|
| 1170 | Â } |
|---|
| 1171 |  else { |
|---|
| 1172 |   MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag; |
|---|
| 1173 |   MBErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, |
|---|
| 1174 |                        sharedh_tag, sharedhs_tag, pstatus_tag); |
|---|
| 1175 | Â |
|---|
| 1176 | Â Â Â // get single-proc destination handles and shared procs |
|---|
| 1177 | Â Â std::vector<int>Â sharing_procs(from_range.size()); |
|---|
| 1178 |   result = mbImpl->tag_get_data(sharedh_tag, from_range, to_vec); |
|---|
| 1179 | Â Â RRA("Failed to get shared handle tag for remote_handles."); |
|---|
| 1180 |   result = mbImpl->tag_get_data(sharedp_tag, from_range, &sharing_procs[0]); |
|---|
| 1181 | Â Â RRA("Failed to get sharing proc tag in remote_handles."); |
|---|
| 1182 |   for (unsigned int j = 0; j < from_range.size(); j++) { |
|---|
| 1183 |    if (to_vec[j] && sharing_procs[j] != to_proc) |
|---|
| 1184 | Â Â Â Â to_vec[j]Â =Â 0; |
|---|
| 1185 | Â Â } |
|---|
| 1186 | Â Â |
|---|
| 1187 | Â Â MBEntityHandle tmp_handles[MAX_SHARING_PROCS]; |
|---|
| 1188 |   int tmp_procs[MAX_SHARING_PROCS]; |
|---|
| 1189 | Â Â Â // go through results, and for 0-valued ones, look for multiple shared proc |
|---|
| 1190 | Â Â MBRange::iterator rit; |
|---|
| 1191 |   unsigned int i; |
|---|
| 1192 |   for (rit = from_range.begin(), i = 0; rit != from_range.end(); rit++, i++) { |
|---|
| 1193 |    if (!to_vec[i]) { |
|---|
| 1194 |     result = mbImpl->tag_get_data(sharedhs_tag, &(*rit), 1, tmp_handles); |
|---|
| 1195 |     if (MB_SUCCESS == result) { |
|---|
| 1196 |      result = mbImpl->tag_get_data(sharedps_tag, &(*rit), 1, tmp_procs); |
|---|
| 1197 | Â Â Â Â Â RRA("Trouble getting sharedps tag."); |
|---|
| 1198 |      for (int j = 0; j < MAX_SHARING_PROCS; j++) |
|---|
| 1199 |       if (tmp_procs[j] == to_proc) { |
|---|
| 1200 | Â Â Â Â Â Â Â to_vec[i]Â =Â tmp_handles[j]; |
|---|
| 1201 | Â Â Â Â Â Â Â break; |
|---|
| 1202 | Â Â Â Â Â Â } |
|---|
| 1203 | Â Â Â Â } |
|---|
| 1204 | Â Â Â |
|---|
| 1205 |     if (!to_vec[i]) { |
|---|
| 1206 |      int j = new_ents.index(*rit); |
|---|
| 1207 |      if (-1 == j) { |
|---|
| 1208 | Â Â Â Â Â Â result =Â MB_FAILURE; |
|---|
| 1209 | Â Â Â Â Â Â RRA("Failed to find new entity in send list."); |
|---|
| 1210 | Â Â Â Â Â } |
|---|
| 1211 |      int err; |
|---|
| 1212 |      to_vec[i] = CREATE_HANDLE(MBMAXTYPE, j, err); |
|---|
| 1213 |      if (err) { |
|---|
| 1214 | Â Â Â Â Â Â result =Â MB_FAILURE; |
|---|
| 1215 | Â Â Â Â Â Â RRA("Failed to create handle in remote_handles."); |
|---|
| 1216 | Â Â Â Â Â } |
|---|
| 1217 | Â Â Â Â } |
|---|
| 1218 | Â Â Â } |
|---|
| 1219 | Â Â } |
|---|
| 1220 | Â } |
|---|
| 1221 | Â |
|---|
| 1222 |  return MB_SUCCESS; |
|---|
| 1223 | } |
|---|
| 1224 | |
|---|
| 1225 | MBErrorCode MBParallelComm::get_remote_handles(const bool store_remote_handles, |
|---|
| 1226 |                         const MBRange &from_range, |
|---|
| 1227 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &to_range, |
|---|
| 1228 |                         int to_proc, |
|---|
| 1229 |                         const MBRange &new_ents) |
|---|
| 1230 | { |
|---|
| 1231 | Â std::vector<MBEntityHandle>Â to_vector(from_range.size()); |
|---|
| 1232 | |
|---|
| 1233 | Â MBErrorCode result = |
|---|
| 1234 |   get_remote_handles(store_remote_handles, from_range, &to_vector[0], |
|---|
| 1235 |             to_proc, new_ents); |
|---|
| 1236 | Â RRA("Trouble getting remote handles."); |
|---|
| 1237 |  std::copy(to_vector.begin(), to_vector.end(), mb_range_inserter(to_range)); |
|---|
| 1238 |  return result; |
|---|
| 1239 | } |
|---|
| 1240 | |
|---|
| 1241 | MBErrorCode MBParallelComm::unpack_entities(unsigned char *&buff_ptr, |
|---|
| 1242 |                       const bool store_remote_handles, |
|---|
| 1243 |                       const int from_proc, |
|---|
| 1244 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &entities)Â |
|---|
| 1245 | { |
|---|
| 1246 | Â MBErrorCode result; |
|---|
| 1247 |  bool done = false; |
|---|
| 1248 | Â MBReadUtilIface *ru =Â NULL; |
|---|
| 1249 |  result = mbImpl->query_interface(std::string("MBReadUtilIface"), |
|---|
| 1250 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â reinterpret_cast<void**>(&ru)); |
|---|
| 1251 | Â RRA("Failed to get MBReadUtilIface."); |
|---|
| 1252 | Â |
|---|
| 1253 | Â |
|---|
| 1254 |  while (!done) { |
|---|
| 1255 | Â Â MBEntityType this_type; |
|---|
| 1256 | Â Â MBEntityHandle actual_start; |
|---|
| 1257 |   UNPACK_INT(buff_ptr, this_type); |
|---|
| 1258 | Â Â assert(this_type >=Â MBVERTEX &&Â |
|---|
| 1259 | Â Â Â Â Â Â (this_type ==Â MBMAXTYPE ||Â this_type <Â MBENTITYSET)); |
|---|
| 1260 | |
|---|
| 1261 | Â Â Â // MBMAXTYPE signifies end of entities data |
|---|
| 1262 |   if (MBMAXTYPE == this_type) break; |
|---|
| 1263 | Â Â |
|---|
| 1264 | Â Â Â // get the number of ents |
|---|
| 1265 |   int num_ents; |
|---|
| 1266 |   UNPACK_INT(buff_ptr, num_ents); |
|---|
| 1267 | Â Â |
|---|
| 1268 |   if (MBVERTEX == this_type) { |
|---|
| 1269 | Â Â Â Â // unpack coords |
|---|
| 1270 |    if (num_ents) { |
|---|
| 1271 | Â Â Â Â std::vector<double*>Â coords(3); |
|---|
| 1272 |     result = ru->get_node_arrays(3, num_ents, 0, |
|---|
| 1273 |                    actual_start, coords); |
|---|
| 1274 | Â Â Â Â RRA("Failed to allocate node arrays."); |
|---|
| 1275 | |
|---|
| 1276 |     entities.insert(actual_start, actual_start+num_ents-1); |
|---|
| 1277 | Â Â Â |
|---|
| 1278 | Â Â Â Â Â // unpack the buffer data directly into coords |
|---|
| 1279 |     for (int i = 0; i < 3; i++) |
|---|
| 1280 |      memcpy(coords[i], buff_ptr+i*num_ents*sizeof(double), |
|---|
| 1281 | Â Â Â Â Â Â Â Â Â num_ents*sizeof(double)); |
|---|
| 1282 | Â Â Â Â buff_ptr +=Â 3*num_ents *Â sizeof(double); |
|---|
| 1283 |     UPC(3*num_ents, " doubles"); |
|---|
| 1284 | |
|---|
| 1285 | Â Â Â Â Â // unpack source handles |
|---|
| 1286 |     if (store_remote_handles) { |
|---|
| 1287 | Â Â Â Â Â MBRange this_range; |
|---|
| 1288 |      this_range.insert(actual_start, actual_start+num_ents-1); |
|---|
| 1289 | Â Â Â Â Â MBRange dum_range; |
|---|
| 1290 |      UNPACK_RANGE(buff_ptr, dum_range); |
|---|
| 1291 |      result = set_remote_data(this_range, dum_range, from_proc); |
|---|
| 1292 | Â Â Â Â Â RRA("Couldn't set sharing data"); |
|---|
| 1293 | Â Â Â Â } |
|---|
| 1294 | Â Â Â } |
|---|
| 1295 | Â Â } |
|---|
| 1296 | |
|---|
| 1297 |   else { |
|---|
| 1298 |    int verts_per_entity; |
|---|
| 1299 | Â Â Â |
|---|
| 1300 | Â Â Â Â // unpack the nodes per entity |
|---|
| 1301 |    UNPACK_INT(buff_ptr, verts_per_entity); |
|---|
| 1302 | Â Â Â |
|---|
| 1303 | Â Â Â MBEntityHandle *connect; |
|---|
| 1304 |    result = ru->get_element_array(num_ents, verts_per_entity, this_type, |
|---|
| 1305 |                    0, actual_start, |
|---|
| 1306 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â connect); |
|---|
| 1307 | Â Â Â RRA("Failed to allocate element arrays."); |
|---|
| 1308 | |
|---|
| 1309 | Â Â Â Â // unpack the connectivity |
|---|
| 1310 |    UNPACK_EH(buff_ptr, connect, (num_ents*verts_per_entity)); |
|---|
| 1311 |    entities.insert(actual_start, actual_start+num_ents-1); |
|---|
| 1312 | |
|---|
| 1313 | Â Â Â Â // convert to local handles |
|---|
| 1314 |    result = get_local_handles(connect, num_ents*verts_per_entity, |
|---|
| 1315 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â entities); |
|---|
| 1316 | Â Â Â RRA("Couldn't get local handles."); |
|---|
| 1317 | |
|---|
| 1318 |    if (store_remote_handles) { |
|---|
| 1319 | Â Â Â Â Â // unpack source handles |
|---|
| 1320 | Â Â Â Â MBRange this_range; |
|---|
| 1321 |     this_range.insert(actual_start, actual_start+num_ents-1); |
|---|
| 1322 | Â Â Â Â MBRange dum_range; |
|---|
| 1323 |     UNPACK_RANGE(buff_ptr, dum_range); |
|---|
| 1324 |     result = set_remote_data(this_range, dum_range, from_proc); |
|---|
| 1325 | Â Â Â Â RRA("Couldn't set sharing data"); |
|---|
| 1326 | Â Â Â } |
|---|
| 1327 | |
|---|
| 1328 | Â Â Â Â // update adjacencies |
|---|
| 1329 |    result = ru->update_adjacencies(actual_start, num_ents, |
|---|
| 1330 |                    verts_per_entity, connect); |
|---|
| 1331 | Â Â Â RRA("Failed to update adjacencies."); |
|---|
| 1332 | Â Â } |
|---|
| 1333 | |
|---|
| 1334 | #ifdef DEBUG_PACKING |
|---|
| 1335 | Â Â Â std::cerr <<Â "Unpacked "Â <<Â num_ents <<Â " ents of type "Â |
|---|
| 1336 | Â Â Â Â Â Â Â Â <<Â MBCN::EntityTypeName(TYPE_FROM_HANDLE(actual_start))Â <<Â std::endl; |
|---|
| 1337 | #endif   |
|---|
| 1338 | |
|---|
| 1339 | Â } |
|---|
| 1340 | Â |
|---|
| 1341 | Â |
|---|
| 1342 |  if (debug_packing) std::cerr << std::endl << "Done unpacking entities." << std::endl; |
|---|
| 1343 | |
|---|
| 1344 |  return MB_SUCCESS; |
|---|
| 1345 | } |
|---|
| 1346 | |
|---|
| 1347 | MBErrorCode MBParallelComm::unpack_iface_entities(unsigned char *&buff_ptr, |
|---|
| 1348 |                          const int from_proc, |
|---|
| 1349 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â std::vector<MBEntityHandle>Â &recd_ents)Â |
|---|
| 1350 | { |
|---|
| 1351 | Â Â // for all the entities in the received buffer; for each, save |
|---|
| 1352 | Â Â // entities in this instance which match connectivity, or zero if none found |
|---|
| 1353 | Â MBErrorCode result; |
|---|
| 1354 |  bool done = false; |
|---|
| 1355 | Â std::vector<MBEntityHandle>Â connect; |
|---|
| 1356 | Â |
|---|
| 1357 |  while (!done) { |
|---|
| 1358 | Â Â MBEntityType this_type; |
|---|
| 1359 |   UNPACK_INT(buff_ptr, this_type); |
|---|
| 1360 | Â Â assert(this_type >Â MBVERTEX &&Â |
|---|
| 1361 | Â Â Â Â Â Â (this_type ==Â MBMAXTYPE ||Â this_type <Â MBENTITYSET)); |
|---|
| 1362 | |
|---|
| 1363 | Â Â Â // MBMAXTYPE signifies end of entities data |
|---|
| 1364 |   if (MBMAXTYPE == this_type) break; |
|---|
| 1365 | Â Â |
|---|
| 1366 | Â Â Â // get the number of ents |
|---|
| 1367 |   int num_ents; |
|---|
| 1368 |   UNPACK_INT(buff_ptr, num_ents); |
|---|
| 1369 | Â Â |
|---|
| 1370 |   int verts_per_entity; |
|---|
| 1371 | Â Â Â |
|---|
| 1372 | Â Â Â // unpack the verts per entity |
|---|
| 1373 |   UNPACK_INT(buff_ptr, verts_per_entity); |
|---|
| 1374 | |
|---|
| 1375 | Â Â connect.resize(verts_per_entity *Â num_ents); |
|---|
| 1376 | Â Â |
|---|
| 1377 | Â Â Â // unpack the connectivity |
|---|
| 1378 |   UNPACK_EH(buff_ptr, &connect[0], (num_ents*verts_per_entity)); |
|---|
| 1379 | |
|---|
| 1380 | Â Â Â // unpack source handles |
|---|
| 1381 |   MBRange source_range, tmp_range; |
|---|
| 1382 |   UNPACK_RANGE(buff_ptr, source_range); |
|---|
| 1383 | |
|---|
| 1384 | Â Â Â // save matching local entities, or 0 if none found |
|---|
| 1385 |   for (int i = 0; i < num_ents; i++) { |
|---|
| 1386 | Â Â Â Â // test for existing entity |
|---|
| 1387 |    result = mbImpl->get_adjacencies(&connect[0]+i*verts_per_entity, verts_per_entity, |
|---|
| 1388 |                     MBCN::Dimension(this_type), false, tmp_range); |
|---|
| 1389 |    if (MB_MULTIPLE_ENTITIES_FOUND == result) { |
|---|
| 1390 | Â Â Â Â RRA("Multiple entities found."); |
|---|
| 1391 | Â Â Â } |
|---|
| 1392 |    if (!tmp_range.empty()) { |
|---|
| 1393 | Â Â Â Â Â // found a corresponding entity - save target |
|---|
| 1394 | Â Â Â Â assert(1Â ==Â tmp_range.size()); |
|---|
| 1395 | Â Â Â Â recd_ents.push_back(*tmp_range.begin()); |
|---|
| 1396 | Â Â Â Â tmp_range.clear(); |
|---|
| 1397 | Â Â Â } |
|---|
| 1398 | Â Â Â else |
|---|
| 1399 | Â Â Â Â recd_ents.push_back(0); |
|---|
| 1400 | Â Â } |
|---|
| 1401 | |
|---|
| 1402 | #ifdef DEBUG_PACKING |
|---|
| 1403 | Â Â std::cerr <<Â "Unpacked "Â <<Â num_ents <<Â " ents of type "Â |
|---|
| 1404 | Â Â Â Â Â Â Â <<Â MBCN::EntityTypeName(TYPE_FROM_HANDLE(actual_start))Â <<Â std::endl; |
|---|
| 1405 | #endif   |
|---|
| 1406 | |
|---|
| 1407 | Â } |
|---|
| 1408 | Â |
|---|
| 1409 | Â |
|---|
| 1410 |  if (debug_packing) std::cerr << std::endl << "Done unpacking iface entities." << std::endl; |
|---|
| 1411 | |
|---|
| 1412 |  return MB_SUCCESS; |
|---|
| 1413 | } |
|---|
| 1414 | |
|---|
| 1415 | MBErrorCode MBParallelComm::get_local_handles(const MBRange &remote_handles, |
|---|
| 1416 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &local_handles, |
|---|
| 1417 |                        const MBRange &new_ents) |
|---|
| 1418 | { |
|---|
| 1419 | Â std::vector<MBEntityHandle>Â rh_vec; |
|---|
| 1420 | Â rh_vec.reserve(remote_handles.size()); |
|---|
| 1421 |  std::copy(remote_handles.begin(), remote_handles.end(), std::back_inserter(rh_vec)); |
|---|
| 1422 |  MBErrorCode result = get_local_handles(&rh_vec[0], remote_handles.size(), new_ents); |
|---|
| 1423 |  std::copy(rh_vec.begin(), rh_vec.end(), mb_range_inserter(local_handles)); |
|---|
| 1424 |  return result; |
|---|
| 1425 | } |
|---|
| 1426 | Â |
|---|
| 1427 | MBErrorCode MBParallelComm::get_local_handles(MBEntityHandle *from_vec, |
|---|
| 1428 |                        int num_ents, |
|---|
| 1429 |                        const MBRange &new_ents) |
|---|
| 1430 | { |
|---|
| 1431 |  for (int i = 0; i < num_ents; i++) { |
|---|
| 1432 |   if (TYPE_FROM_HANDLE(from_vec[i]) == MBMAXTYPE) { |
|---|
| 1433 | Â Â Â assert(ID_FROM_HANDLE(from_vec[i])Â <Â (int)Â new_ents.size()); |
|---|
| 1434 | Â Â Â from_vec[i]Â =Â new_ents[ID_FROM_HANDLE(from_vec[i])]; |
|---|
| 1435 | Â Â } |
|---|
| 1436 | Â } |
|---|
| 1437 | Â |
|---|
| 1438 |  return MB_SUCCESS; |
|---|
| 1439 | } |
|---|
| 1440 | |
|---|
| 1441 | MBErrorCode MBParallelComm::set_remote_data(MBRange &local_range, |
|---|
| 1442 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &remote_range, |
|---|
| 1443 |                       int other_proc) |
|---|
| 1444 | { |
|---|
| 1445 | Â Â // NOTE: THIS IMPLEMENTATION IS JUST LIKE THE VECTOR-BASED VERSION, NO REUSE |
|---|
| 1446 | Â Â // AT THIS TIME, SO IF YOU FIX A BUG IN THIS VERSION, IT MAY BE IN THE |
|---|
| 1447 | Â Â // OTHER VERSION TOO!!! |
|---|
| 1448 | |
|---|
| 1449 |  MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag; |
|---|
| 1450 |  MBErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, |
|---|
| 1451 |                       sharedh_tag, sharedhs_tag, pstatus_tag); |
|---|
| 1452 | |
|---|
| 1453 | Â Â // get remote procs tag, if any |
|---|
| 1454 |  MBRange tmp_range, tmp_local_range = local_range; |
|---|
| 1455 | Â std::vector<int>Â remote_proc(local_range.size()); |
|---|
| 1456 | Â std::vector<int>Â remote_procs(MAX_SHARING_PROCS); |
|---|
| 1457 | Â std::vector<MBEntityHandle>Â remote_handle(local_range.size()); |
|---|
| 1458 | Â std::vector<MBEntityHandle>Â remote_handles(MAX_SHARING_PROCS); |
|---|
| 1459 |  std::fill(remote_procs.begin(), remote_procs.end(), -1); |
|---|
| 1460 |  std::fill(remote_handles.begin(), remote_handles.end(), 0); |
|---|
| 1461 |  result = mbImpl->tag_get_data(sharedp_tag, local_range, |
|---|
| 1462 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &remote_proc[0]); |
|---|
| 1463 | Â RRA("Couldn't get sharedp tag (range)."); |
|---|
| 1464 |  result = mbImpl->tag_get_data(sharedh_tag, local_range, |
|---|
| 1465 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &remote_handle[0]); |
|---|
| 1466 | Â RRA("Couldn't get sharedh tag (range)."); |
|---|
| 1467 |  MBRange::iterator rit, rit2; |
|---|
| 1468 |  int i = 0; |
|---|
| 1469 | |
|---|
| 1470 | Â Â // for each pair of local/remote handles: |
|---|
| 1471 |  for (rit = tmp_local_range.begin(), rit2 = remote_range.begin(); |
|---|
| 1472 |     rit != tmp_local_range.end(); rit++, rit2++, i++) { |
|---|
| 1473 | |
|---|
| 1474 | Â Â Â // get existing remote proc(s), handle(s) for this local handle |
|---|
| 1475 | Â Â remote_procs[0]Â =Â remote_proc[i]; |
|---|
| 1476 |   if (-1 != remote_procs[0]) remote_handles[0] = remote_handle[i]; |
|---|
| 1477 |   else { |
|---|
| 1478 |    result = mbImpl->tag_get_data(sharedps_tag, &(*rit), 1, |
|---|
| 1479 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &remote_procs[0]); |
|---|
| 1480 |    if (MB_SUCCESS == result) { |
|---|
| 1481 |     result = mbImpl->tag_get_data(sharedhs_tag, &(*rit), 1, |
|---|
| 1482 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &remote_handles[0]); |
|---|
| 1483 | Â Â Â Â RRA("Couldn't get sharedhs tag (range)."); |
|---|
| 1484 | Â Â Â } |
|---|
| 1485 | Â Â } |
|---|
| 1486 | |
|---|
| 1487 | Â Â Â // now insert other_proc, handle into these, and set the tags |
|---|
| 1488 |   if (-1 == remote_procs[0]) { |
|---|
| 1489 | Â Â Â remote_procs[0]Â =Â other_proc; |
|---|
| 1490 | Â Â Â remote_handles[0]Â =Â *rit2; |
|---|
| 1491 |    result = mbImpl->tag_set_data(sharedp_tag, &(*rit), 1, &remote_procs[0]); |
|---|
| 1492 | Â Â Â RRA("Couldn't set sharedp tag (range)"); |
|---|
| 1493 |    result = mbImpl->tag_set_data(sharedh_tag, &(*rit), 1, &remote_handles[0]); |
|---|
| 1494 | Â Â Â RRA("Couldn't set sharedh tag (range)"); |
|---|
| 1495 | Â Â Â remote_procs[0]Â =Â -1; |
|---|
| 1496 | Â Â Â remote_handles[0]Â =Â 0; |
|---|
| 1497 | Â Â } |
|---|
| 1498 |   else { |
|---|
| 1499 | Â Â Â std::vector<int>::iterator vit =Â remote_procs.begin(); |
|---|
| 1500 | Â Â Â std::vector<MBEntityHandle>::iterator vit2 =Â remote_handles.begin(); |
|---|
| 1501 |    while (-1 != *vit && vit != remote_procs.end() && other_proc > *vit) { |
|---|
| 1502 | Â Â Â Â vit++;Â vit2++; |
|---|
| 1503 | Â Â Â } |
|---|
| 1504 | Â Â Â assert(*vit !=Â other_proc); |
|---|
| 1505 |    remote_procs.insert(vit, other_proc); |
|---|
| 1506 |    remote_handles.insert(vit2, *rit2); |
|---|
| 1507 | Â Â Â Â // need to pop 'cuz we're using an insert above |
|---|
| 1508 | Â Â Â remote_procs.pop_back(); |
|---|
| 1509 | Â Â Â remote_handles.pop_back(); |
|---|
| 1510 |    result = mbImpl->tag_set_data(sharedps_tag, &(*rit), 1, &remote_procs[0]); |
|---|
| 1511 | Â Â Â RRA("Couldn't set sharedps tag (range)"); |
|---|
| 1512 |    result = mbImpl->tag_set_data(sharedhs_tag, &(*rit), 1, &remote_handles[0]); |
|---|
| 1513 | Â Â Â RRA("Couldn't set sharedhs tag (range)"); |
|---|
| 1514 |    std::fill(remote_procs.begin(), remote_procs.end(), -1); |
|---|
| 1515 |    std::fill(remote_handles.begin(), remote_handles.end(), 0); |
|---|
| 1516 | Â Â Â Â // need to clear sharedp_tag and sharedh_tag if prev |
|---|
| 1517 | Â Â Â Â // data came from there |
|---|
| 1518 |    if (-1 != remote_proc[i]) { |
|---|
| 1519 | Â Â Â Â remote_proc[i]Â =Â -1; |
|---|
| 1520 | Â Â Â Â remote_handle[i]Â =Â 0; |
|---|
| 1521 |     result = mbImpl->tag_set_data(sharedp_tag, &*rit, 1, &remote_proc[i] ); |
|---|
| 1522 | Â Â Â Â RRA("Couldn't set sharedp tag"); |
|---|
| 1523 |     result = mbImpl->tag_set_data(sharedh_tag, &*rit, 1, &remote_handle[i] ); |
|---|
| 1524 | Â Â Â Â RRA("Couldn't set sharedp tag"); |
|---|
| 1525 | Â Â Â } |
|---|
| 1526 | Â Â } |
|---|
| 1527 | Â } |
|---|
| 1528 | |
|---|
| 1529 | Â Â // also update shared flag for these ents |
|---|
| 1530 |  unsigned char *shared_flags = (unsigned char*) &remote_proc[0]; |
|---|
| 1531 |  result = mbImpl->tag_get_data(pstatus_tag, local_range, shared_flags); |
|---|
| 1532 | Â RRA("Couldn't get pstatus tag (range)"); |
|---|
| 1533 |  for (unsigned int i = 0; i < local_range.size(); i++) |
|---|
| 1534 | Â Â shared_flags[i]Â |=Â PSTATUS_SHARED; |
|---|
| 1535 |  result = mbImpl->tag_set_data(pstatus_tag, local_range, shared_flags); |
|---|
| 1536 | Â RRA("Couldn't set pstatus tag (range)"); |
|---|
| 1537 | Â |
|---|
| 1538 | Â |
|---|
| 1539 |  return MB_SUCCESS; |
|---|
| 1540 | } |
|---|
| 1541 | Â |
|---|
| 1542 | MBErrorCode MBParallelComm::set_remote_data(MBEntityHandle *local_ents, |
|---|
| 1543 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBEntityHandle *remote_ents, |
|---|
| 1544 |                       int num_ents, |
|---|
| 1545 |                       int other_proc) |
|---|
| 1546 | { |
|---|
| 1547 |  if (0 == num_ents) |
|---|
| 1548 |   return MB_SUCCESS; |
|---|
| 1549 | |
|---|
| 1550 | Â Â // NOTE: THIS IMPLEMENTATION IS JUST LIKE THE RANGE-BASED VERSION, NO REUSE |
|---|
| 1551 | Â Â // AT THIS TIME, SO IF YOU FIX A BUG IN THIS VERSION, IT MAY BE IN THE |
|---|
| 1552 | Â Â // OTHER VERSION TOO!!! |
|---|
| 1553 |  MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag; |
|---|
| 1554 |  MBErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, |
|---|
| 1555 |                       sharedh_tag, sharedhs_tag, pstatus_tag); |
|---|
| 1556 | |
|---|
| 1557 | Â Â // get remote procs tag, if any |
|---|
| 1558 | Â MBRange tmp_range; |
|---|
| 1559 | Â std::vector<int>Â remote_proc(num_ents); |
|---|
| 1560 |  int remote_procs[MAX_SHARING_PROCS]; |
|---|
| 1561 | Â std::vector<MBEntityHandle>Â remote_handle(num_ents); |
|---|
| 1562 | Â MBEntityHandle remote_handles[MAX_SHARING_PROCS]; |
|---|
| 1563 |  std::vector<unsigned char> pstatus_vals(num_ents); |
|---|
| 1564 |  result = mbImpl->tag_get_data(sharedp_tag, local_ents, num_ents, |
|---|
| 1565 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &remote_proc[0]); |
|---|
| 1566 | Â RRA("Couldn't get sharedp tag (vector)"); |
|---|
| 1567 |  result = mbImpl->tag_get_data(sharedh_tag, local_ents, num_ents, |
|---|
| 1568 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &remote_handle[0]); |
|---|
| 1569 | Â RRA("Couldn't get sharedh tag (vector)"); |
|---|
| 1570 |  result = mbImpl->tag_get_data(pstatus_tag, local_ents, num_ents, |
|---|
| 1571 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &pstatus_vals[0]); |
|---|
| 1572 | Â RRA("Couldn't get sharedh tag (vector)"); |
|---|
| 1573 | |
|---|
| 1574 | Â Â // for each local/remote handle pair |
|---|
| 1575 |  for (int i = 0; i != num_ents; i++) { |
|---|
| 1576 | |
|---|
| 1577 | Â Â Â // get existing remote proc(s), handle(s) for this local handle |
|---|
| 1578 |   if (-1 != remote_proc[i]) { |
|---|
| 1579 | Â Â Â remote_procs[0]Â =Â remote_proc[i]; |
|---|
| 1580 | Â Â Â remote_handles[0]Â =Â remote_handle[i]; |
|---|
| 1581 |    std::fill(remote_procs+1, remote_procs+MAX_SHARING_PROCS, -1); |
|---|
| 1582 |    std::fill(remote_handles+1, remote_handles+MAX_SHARING_PROCS, 0); |
|---|
| 1583 | Â Â } |
|---|
| 1584 |   else { |
|---|
| 1585 |    result = mbImpl->tag_get_data(sharedps_tag, local_ents+i, 1, |
|---|
| 1586 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â remote_procs); |
|---|
| 1587 | Â Â Â RRA("Couldn't get sharedps tag (vector)"); |
|---|
| 1588 | Â Â Â |
|---|
| 1589 |    result = mbImpl->tag_get_data(sharedhs_tag, local_ents+i, 1, |
|---|
| 1590 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â remote_handles); |
|---|
| 1591 | Â Â Â RRA("Couldn't get sharedhs tag (vector)"); |
|---|
| 1592 | Â Â } |
|---|
| 1593 | |
|---|
| 1594 | Â Â Â // now either insert other_proc, handle into these, or remove if |
|---|
| 1595 | Â Â Â // remote handle is 0 |
|---|
| 1596 |   if (0 == remote_ents[i]) { |
|---|
| 1597 |    result = rmv_remote_proc(local_ents[i], remote_procs, remote_handles, |
|---|
| 1598 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â other_proc); |
|---|
| 1599 | Â Â Â RRA(" "); |
|---|
| 1600 | Â Â } |
|---|
| 1601 |   else { |
|---|
| 1602 |    result = add_remote_proc(local_ents[i], remote_procs, remote_handles, |
|---|
| 1603 |                 other_proc, remote_ents[i]); |
|---|
| 1604 | Â Â Â RRA(" "); |
|---|
| 1605 | Â Â } |
|---|
| 1606 | Â } |
|---|
| 1607 | |
|---|
| 1608 |  return MB_SUCCESS; |
|---|
| 1609 | } |
|---|
| 1610 | |
|---|
| 1611 | MBErrorCode MBParallelComm::rmv_remote_proc(MBEntityHandle ent, |
|---|
| 1612 |                       int *remote_procs, |
|---|
| 1613 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBEntityHandle *remote_hs, |
|---|
| 1614 |                       int remote_proc) |
|---|
| 1615 | { |
|---|
| 1616 |  int i = std::find(remote_procs, remote_procs+MAX_SHARING_PROCS, -1) - remote_procs; |
|---|
| 1617 |  int j = std::find(remote_procs, remote_procs+i, remote_proc) - remote_procs; |
|---|
| 1618 | Â MBErrorCode result; |
|---|
| 1619 | |
|---|
| 1620 | Â Â // remote_proc must be in this list |
|---|
| 1621 | Â assert(j !=Â i); |
|---|
| 1622 | Â |
|---|
| 1623 |  for (; j != i; j++) { |
|---|
| 1624 | Â Â remote_procs[j]Â =Â remote_procs[j+1]; |
|---|
| 1625 | Â Â remote_hs[j]Â =Â remote_hs[j+1]; |
|---|
| 1626 | Â } |
|---|
| 1627 | |
|---|
| 1628 |  if (i == 1) { |
|---|
| 1629 | Â Â Â // only had one proc, and now have none; have to set the values, |
|---|
| 1630 | Â Â Â // since they're sparse tags |
|---|
| 1631 |   result = mbImpl->tag_set_data(sharedp_tag(), &ent, 1, remote_procs); |
|---|
| 1632 |   result = mbImpl->tag_set_data(sharedh_tag(), &ent, 1, remote_hs); |
|---|
| 1633 | Â Â Â // if it's not shared, it's also not a ghost, interface, or !owned entity |
|---|
| 1634 |   unsigned char not_shared = 0; |
|---|
| 1635 |   result = mbImpl->tag_set_data(pstatus_tag(), &ent, 1, ¬_shared); |
|---|
| 1636 | Â } |
|---|
| 1637 |  else if (i == 2) { |
|---|
| 1638 | Â Â Â // went from 2 to 1, need to unset 1 and set the other |
|---|
| 1639 |   result = mbImpl->tag_set_data(sharedp_tag(), &ent, 1, remote_procs); |
|---|
| 1640 | Â Â RRA("Couldn't set sharedp tag"); |
|---|
| 1641 |   result = mbImpl->tag_set_data(sharedh_tag(), &ent, 1, remote_hs); |
|---|
| 1642 | Â Â RRA("Couldn't set sharedh tag"); |
|---|
| 1643 |   result = mbImpl->tag_delete_data(sharedps_tag(), &ent, 1); |
|---|
| 1644 | Â Â RRA("Couldn't remove sharedps tag"); |
|---|
| 1645 |   result = mbImpl->tag_delete_data(sharedhs_tag(), &ent, 1); |
|---|
| 1646 | Â Â RRA("Couldn't remove sharedhs tag"); |
|---|
| 1647 | Â } |
|---|
| 1648 |  else { |
|---|
| 1649 |   result = mbImpl->tag_set_data(sharedps_tag(), &ent, 1, remote_procs); |
|---|
| 1650 | Â Â RRA("Couldn't set sharedps tag"); |
|---|
| 1651 |   result = mbImpl->tag_set_data(sharedhs_tag(), &ent, 1, remote_hs); |
|---|
| 1652 | Â Â RRA("Couldn't set sharedhs tag"); |
|---|
| 1653 | Â } |
|---|
| 1654 | Â |
|---|
| 1655 |  return MB_SUCCESS; |
|---|
| 1656 | } |
|---|
| 1657 | |
|---|
| 1658 | template <typename T> void |
|---|
| 1659 | insert_in_array( T* array, size_t array_size, size_t location, T value ) |
|---|
| 1660 | { |
|---|
| 1661 | Â assert(Â location+1Â <Â array_size ); |
|---|
| 1662 |  for (size_t i = array_size-1; i > location; --i) |
|---|
| 1663 | Â Â array[i]Â =Â array[i-1]; |
|---|
| 1664 | Â array[location]Â =Â value; |
|---|
| 1665 | } |
|---|
| 1666 | |
|---|
| 1667 | MBErrorCode MBParallelComm::add_remote_proc(MBEntityHandle ent, |
|---|
| 1668 |                       int *remote_procs, |
|---|
| 1669 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBEntityHandle *remote_hs, |
|---|
| 1670 |                       int remote_proc, |
|---|
| 1671 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBEntityHandle remote_handle)Â |
|---|
| 1672 | { |
|---|
| 1673 |  int* ptr = std::find( remote_procs, remote_procs+MAX_SHARING_PROCS, -1 ); |
|---|
| 1674 |  const size_t n = ptr - remote_procs; |
|---|
| 1675 |  ptr = std::lower_bound( remote_procs, remote_procs+n, remote_proc ); |
|---|
| 1676 |  const size_t i = ptr - remote_procs; |
|---|
| 1677 | Â |
|---|
| 1678 | Â MBErrorCode result; |
|---|
| 1679 |  const int invalid_proc = -1; |
|---|
| 1680 |  const MBEntityHandle invalid_handle = 0; |
|---|
| 1681 |  if (i == n || remote_procs[i] != remote_proc) { |
|---|
| 1682 |   insert_in_array( remote_procs, MAX_SHARING_PROCS, i, remote_proc ); |
|---|
| 1683 |   insert_in_array( remote_hs, MAX_SHARING_PROCS, i, remote_handle ); |
|---|
| 1684 | Â Â |
|---|
| 1685 |   switch (n) { |
|---|
| 1686 |    case 0: |
|---|
| 1687 |     result = mbImpl->tag_set_data( sharedp_tag(), &ent, 1, remote_procs ); |
|---|
| 1688 | Â Â Â Â RRA("Couldn't set sharedp tag"); |
|---|
| 1689 |     result = mbImpl->tag_set_data( sharedh_tag(), &ent, 1, remote_hs ); |
|---|
| 1690 | Â Â Â Â RRA("Couldn't set sharedh tag"); |
|---|
| 1691 | Â Â Â Â break; |
|---|
| 1692 |    case 1: |
|---|
| 1693 | Â Â Â Â Â // going from 1 -> many, so clear single-value tag |
|---|
| 1694 |     result = mbImpl->tag_set_data( sharedp_tag(), &ent, 1, &invalid_proc ); |
|---|
| 1695 | Â Â Â Â RRA("Couldn't set sharedp tag"); |
|---|
| 1696 |     result = mbImpl->tag_set_data( sharedh_tag(), &ent, 1, &invalid_handle ); |
|---|
| 1697 | Â Â Â Â RRA("Couldn't set sharedh tag"); |
|---|
| 1698 | Â Â Â Â Â // NO BREAK: fall through to next block to set many-valued tags |
|---|
| 1699 | Â Â Â default: |
|---|
| 1700 |     result = mbImpl->tag_set_data( sharedps_tag(), &ent, 1, remote_procs ); |
|---|
| 1701 | Â Â Â Â RRA("Couldn't set sharedps tag"); |
|---|
| 1702 |     result = mbImpl->tag_set_data( sharedhs_tag(), &ent, 1, remote_hs ); |
|---|
| 1703 | Â Â Â Â RRA("Couldn't set sharedhs tag"); |
|---|
| 1704 | Â Â Â Â break; |
|---|
| 1705 | Â Â } |
|---|
| 1706 | Â } |
|---|
| 1707 |  else if (remote_hs[i] != remote_handle) { |
|---|
| 1708 | Â Â assert(remote_hs[i]Â ==Â invalid_handle); |
|---|
| 1709 | Â Â remote_hs[i]Â =Â remote_handle; |
|---|
| 1710 |   if (n == 1) { |
|---|
| 1711 |    result = mbImpl->tag_set_data( sharedh_tag(), &ent, 1, remote_hs ); |
|---|
| 1712 | Â Â Â RRA("Couldn't set sharedh tag"); |
|---|
| 1713 | Â Â } |
|---|
| 1714 |   else { |
|---|
| 1715 |    result = mbImpl->tag_set_data( sharedhs_tag(), &ent, 1, remote_hs ); |
|---|
| 1716 | Â Â Â RRA("Couldn't set sharedhs tag"); |
|---|
| 1717 | Â Â } |
|---|
| 1718 | Â } |
|---|
| 1719 | Â |
|---|
| 1720 |  return MB_SUCCESS; |
|---|
| 1721 | } |
|---|
| 1722 | |
|---|
| 1723 | MBErrorCode MBParallelComm::pack_range_map(MBRange &key_range, MBEntityHandle val_start, |
|---|
| 1724 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â HandleMap &handle_map)Â |
|---|
| 1725 | { |
|---|
| 1726 |  for (MBRange::const_pair_iterator key_it = key_range.const_pair_begin(); |
|---|
| 1727 | Â Â Â Â key_it !=Â key_range.const_pair_end();Â key_it++)Â { |
|---|
| 1728 |   int tmp_num = (*key_it).second - (*key_it).first + 1; |
|---|
| 1729 |   handle_map.insert((*key_it).first, val_start, tmp_num); |
|---|
| 1730 | Â Â val_start +=Â tmp_num; |
|---|
| 1731 | Â } |
|---|
| 1732 | |
|---|
| 1733 |  return MB_SUCCESS; |
|---|
| 1734 | } |
|---|
| 1735 | |
|---|
| 1736 | MBErrorCode MBParallelComm::pack_sets(MBRange &entities, |
|---|
| 1737 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange::const_iterator &start_rit, |
|---|
| 1738 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &whole_range, |
|---|
| 1739 |                    unsigned char *&buff_ptr, |
|---|
| 1740 |                    int &count, |
|---|
| 1741 |                    const bool just_count, |
|---|
| 1742 |                    const bool store_remote_handles, |
|---|
| 1743 |                    const int to_proc, |
|---|
| 1744 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &set_range, |
|---|
| 1745 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â std::vector<MBRange>Â &set_ranges, |
|---|
| 1746 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â std::vector<int>Â &set_sizes, |
|---|
| 1747 |                    std::vector<unsigned int> &options_vec) |
|---|
| 1748 | { |
|---|
| 1749 | Â Â // SETS: |
|---|
| 1750 | Â Â // . #sets |
|---|
| 1751 | Â Â // . for each set: |
|---|
| 1752 | Â Â //Â Â - options[#sets] (unsigned int) |
|---|
| 1753 | Â Â //Â Â - if (unordered) set range |
|---|
| 1754 | Â Â //Â Â - else if ordered |
|---|
| 1755 | Â Â //Â Â Â . #ents in set |
|---|
| 1756 | Â Â //Â Â Â . handles[#ents] |
|---|
| 1757 | Â Â //Â Â - #parents |
|---|
| 1758 | Â Â //Â Â - if (#parents) handles[#parents] |
|---|
| 1759 | Â Â //Â Â - #children |
|---|
| 1760 | Â Â //Â Â - if (#children) handles[#children] |
|---|
| 1761 | Â |
|---|
| 1762 | Â Â // now the sets; assume any sets the application wants to pass are in the entities list |
|---|
| 1763 |  unsigned char *orig_buff_ptr = buff_ptr; |
|---|
| 1764 | Â MBErrorCode result; |
|---|
| 1765 | |
|---|
| 1766 |  if (just_count) { |
|---|
| 1767 |   int ranges_size = 0, vecs_size = 0, tot_parch = 0; |
|---|
| 1768 | Â Â |
|---|
| 1769 |   for (; start_rit != entities.end(); start_rit++) { |
|---|
| 1770 | Â Â Â set_range.insert(*start_rit); |
|---|
| 1771 | Â Â |
|---|
| 1772 |    unsigned int options; |
|---|
| 1773 |    result = mbImpl->get_meshset_options(*start_rit, options); |
|---|
| 1774 | Â Â Â RRA("Failed to get meshset options."); |
|---|
| 1775 | Â Â Â options_vec.push_back(options); |
|---|
| 1776 | |
|---|
| 1777 |    if (options & MESHSET_SET) { |
|---|
| 1778 | Â Â Â Â Â // range-based set; count the subranges |
|---|
| 1779 | Â Â Â Â set_ranges.push_back(MBRange()); |
|---|
| 1780 |     result = mbImpl->get_entities_by_handle(*start_rit, *set_ranges.rbegin()); |
|---|
| 1781 | Â Â Â Â RRA("Failed to get set entities."); |
|---|
| 1782 | |
|---|
| 1783 | Â Â Â Â Â // set range |
|---|
| 1784 | Â Â Â Â ranges_size +=Â 2Â *Â sizeof(MBEntityHandle)Â *Â num_subranges(*set_ranges.rbegin())Â +Â |
|---|
| 1785 | Â Â Â Â Â sizeof(int); |
|---|
| 1786 | Â Â Â } |
|---|
| 1787 |    else if (options & MESHSET_ORDERED) { |
|---|
| 1788 | Â Â Â Â Â // just get the number of entities in the set |
|---|
| 1789 |     int num_ents; |
|---|
| 1790 |     result = mbImpl->get_number_entities_by_handle(*start_rit, num_ents); |
|---|
| 1791 | Â Â Â Â RRA("Failed to get number entities in ordered set."); |
|---|
| 1792 | Â Â Â Â set_sizes.push_back(num_ents); |
|---|
| 1793 | |
|---|
| 1794 | Â Â Â Â Â // set vec |
|---|
| 1795 | Â Â Â Â vecs_size +=Â sizeof(MBEntityHandle)Â *Â num_ents +Â sizeof(int); |
|---|
| 1796 | Â Â Â } |
|---|
| 1797 | |
|---|
| 1798 | Â Â Â Â // get numbers of parents/children |
|---|
| 1799 |    int num_par, num_ch; |
|---|
| 1800 |    result = mbImpl->num_child_meshsets(*start_rit, &num_ch); |
|---|
| 1801 | Â Â Â RRA("Failed to get num children."); |
|---|
| 1802 | |
|---|
| 1803 |    result = mbImpl->num_parent_meshsets(*start_rit, &num_par); |
|---|
| 1804 | Â Â Â RRA("Failed to get num parents."); |
|---|
| 1805 | |
|---|
| 1806 | Â Â Â tot_parch +=Â num_ch +Â num_par; |
|---|
| 1807 | Â Â Â |
|---|
| 1808 | Â Â } |
|---|
| 1809 | |
|---|
| 1810 | Â Â Â // num of sets |
|---|
| 1811 | Â Â count +=Â sizeof(int); |
|---|
| 1812 | Â Â |
|---|
| 1813 | Â Â Â // options |
|---|
| 1814 |   count += set_range.size() * sizeof(unsigned int); |
|---|
| 1815 | |
|---|
| 1816 | Â Â Â // range, vector sizes |
|---|
| 1817 | Â Â count +=Â ranges_size +Â vecs_size; |
|---|
| 1818 | Â Â |
|---|
| 1819 | Â Â Â // set children, parents |
|---|
| 1820 | Â Â count +=Â 2Â *Â set_range.size()Â *Â sizeof(int)Â +Â tot_parch *Â sizeof(MBEntityHandle); |
|---|
| 1821 | |
|---|
| 1822 | Â Â Â Â // set handles |
|---|
| 1823 |   if (!set_range.empty() && store_remote_handles) |
|---|
| 1824 | Â Â Â count +=Â sizeof(int)Â +Â 2*sizeof(MBEntityHandle)*num_subranges(set_range); |
|---|
| 1825 | |
|---|
| 1826 | Â Â whole_range.merge(set_range); |
|---|
| 1827 | Â } |
|---|
| 1828 |  else { |
|---|
| 1829 | Â Â |
|---|
| 1830 | Â Â Â // set handle range |
|---|
| 1831 |   PACK_INT(buff_ptr, set_range.size()); |
|---|
| 1832 | |
|---|
| 1833 | Â Â Â // option values |
|---|
| 1834 |   if (!set_range.empty()) |
|---|
| 1835 |    PACK_VOID(buff_ptr, &options_vec[0], set_range.size()*sizeof(unsigned int)); |
|---|
| 1836 | |
|---|
| 1837 |   std::vector<unsigned int>::const_iterator opt_it = options_vec.begin(); |
|---|
| 1838 | Â Â std::vector<MBRange>::const_iterator rit =Â set_ranges.begin(); |
|---|
| 1839 | Â Â std::vector<int>::const_iterator mem_it =Â set_sizes.begin(); |
|---|
| 1840 |   static std::vector<MBEntityHandle> members; |
|---|
| 1841 | |
|---|
| 1842 |   for (MBRange::const_iterator set_it = set_range.begin(); set_it != set_range.end(); |
|---|
| 1843 |      set_it++, opt_it++) { |
|---|
| 1844 |    if ((*opt_it) & MESHSET_SET) { |
|---|
| 1845 | Â Â Â Â Â // pack entities as a range |
|---|
| 1846 | Â Â Â Â MBRange dum_range; |
|---|
| 1847 | Â Â Â Â result =Â get_remote_handles(store_remote_handles, |
|---|
| 1848 |                   (*rit), dum_range, to_proc, |
|---|
| 1849 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â whole_range); |
|---|
| 1850 | Â Â Â Â RRA("Trouble getting remote handles for unordered set contents."); |
|---|
| 1851 |     PACK_RANGE(buff_ptr, dum_range); |
|---|
| 1852 | Â Â Â Â rit++; |
|---|
| 1853 | Â Â Â } |
|---|
| 1854 |    else if ((*opt_it) & MESHSET_ORDERED) { |
|---|
| 1855 | Â Â Â Â Â // pack entities as vector, with length |
|---|
| 1856 |     PACK_INT(buff_ptr, *mem_it); |
|---|
| 1857 | Â Â Â Â members.clear(); |
|---|
| 1858 |     result = mbImpl->get_entities_by_handle(*set_it, members); |
|---|
| 1859 | Â Â Â Â RRA("Failed to get set entities."); |
|---|
| 1860 | Â Â Â Â result =Â get_remote_handles(store_remote_handles, |
|---|
| 1861 |                   &members[0], &members[0], |
|---|
| 1862 |                   members.size(), to_proc, |
|---|
| 1863 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â whole_range); |
|---|
| 1864 | Â Â Â Â RRA("Trouble getting remote handles for ordered set contents."); |
|---|
| 1865 |     PACK_EH(buff_ptr, &members[0], *mem_it); |
|---|
| 1866 | Â Â Â Â mem_it++; |
|---|
| 1867 | Â Â Â } |
|---|
| 1868 | Â Â } |
|---|
| 1869 | Â Â |
|---|
| 1870 | Â Â Â // pack numbers of parents/children |
|---|
| 1871 |   unsigned int tot_pch = 0; |
|---|
| 1872 |   for (MBRange::const_iterator set_it = set_range.begin(); set_it != set_range.end(); |
|---|
| 1873 | Â Â Â Â Â set_it++)Â { |
|---|
| 1874 | Â Â Â Â // pack parents |
|---|
| 1875 |    int num_pch; |
|---|
| 1876 |    result = mbImpl->num_parent_meshsets(*set_it, &num_pch); |
|---|
| 1877 | Â Â Â RRA("Failed to get num parents."); |
|---|
| 1878 |    PACK_INT(buff_ptr, num_pch); |
|---|
| 1879 | Â Â Â tot_pch +=Â num_pch; |
|---|
| 1880 |    result = mbImpl->num_child_meshsets(*set_it, &num_pch); |
|---|
| 1881 | Â Â Â RRA("Failed to get num children."); |
|---|
| 1882 |    PACK_INT(buff_ptr, num_pch); |
|---|
| 1883 | Â Â Â tot_pch +=Â num_pch; |
|---|
| 1884 | Â Â } |
|---|
| 1885 | |
|---|
| 1886 | Â Â Â // now pack actual parents/children |
|---|
| 1887 | Â Â members.clear(); |
|---|
| 1888 | Â Â members.reserve(tot_pch); |
|---|
| 1889 | Â Â std::vector<MBEntityHandle>Â tmp_pch; |
|---|
| 1890 |   for (MBRange::const_iterator set_it = set_range.begin(); set_it != set_range.end(); |
|---|
| 1891 | Â Â Â Â Â set_it++)Â { |
|---|
| 1892 |    result = mbImpl->get_parent_meshsets(*set_it, tmp_pch); |
|---|
| 1893 | Â Â Â RRA("Failed to get parents."); |
|---|
| 1894 |    std::copy(tmp_pch.begin(), tmp_pch.end(), std::back_inserter(members)); |
|---|
| 1895 | Â Â Â tmp_pch.clear(); |
|---|
| 1896 |    result = mbImpl->get_child_meshsets(*set_it, tmp_pch); |
|---|
| 1897 | Â Â Â RRA("Failed to get children."); |
|---|
| 1898 |    std::copy(tmp_pch.begin(), tmp_pch.end(), std::back_inserter(members)); |
|---|
| 1899 | Â Â Â tmp_pch.clear(); |
|---|
| 1900 | Â Â } |
|---|
| 1901 | Â Â assert(members.size()Â ==Â tot_pch); |
|---|
| 1902 |   if (!members.empty()) { |
|---|
| 1903 | Â Â Â result =Â get_remote_handles(store_remote_handles, |
|---|
| 1904 |                  &members[0], &members[0], |
|---|
| 1905 |                  members.size(), to_proc, |
|---|
| 1906 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â whole_range); |
|---|
| 1907 | Â Â Â RRA("Trouble getting remote handles for set parent/child sets."); |
|---|
| 1908 | #ifndef NDEBUG |
|---|
| 1909 | Â Â Â Â // check that all handles are either sets or maxtype |
|---|
| 1910 |    for (unsigned int __j = 0; __j < members.size(); __j++) |
|---|
| 1911 | Â Â Â Â assert((TYPE_FROM_HANDLE(members[__j])Â ==Â MBMAXTYPE && |
|---|
| 1912 | Â Â Â Â Â Â Â Â ID_FROM_HANDLE(members[__j])Â <Â (int)whole_range.size())Â || |
|---|
| 1913 | Â Â Â Â Â Â Â Â TYPE_FROM_HANDLE(members[__j])Â ==Â MBENTITYSET); |
|---|
| 1914 | #endif    |
|---|
| 1915 |    PACK_EH(buff_ptr, &members[0], members.size()); |
|---|
| 1916 | Â Â } |
|---|
| 1917 | Â Â |
|---|
| 1918 | Â Â // pack the handles |
|---|
| 1919 |   if (store_remote_handles && !set_range.empty()) |
|---|
| 1920 |    PACK_RANGE(buff_ptr, set_range); |
|---|
| 1921 | |
|---|
| 1922 | Â Â count +=Â buff_ptr -Â orig_buff_ptr; |
|---|
| 1923 | Â } |
|---|
| 1924 | |
|---|
| 1925 |  if (debug_packing) std::cerr << std::endl << "Done packing sets." << std::endl; |
|---|
| 1926 | |
|---|
| 1927 |  return MB_SUCCESS; |
|---|
| 1928 | } |
|---|
| 1929 | |
|---|
| 1930 | MBErrorCode MBParallelComm::unpack_sets(unsigned char *&buff_ptr, |
|---|
| 1931 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &entities, |
|---|
| 1932 |                     const bool store_remote_handles, |
|---|
| 1933 |                     const int from_proc) |
|---|
| 1934 | { |
|---|
| 1935 | Â |
|---|
| 1936 | Â Â // now the sets; assume any sets the application wants to pass are in the entities list |
|---|
| 1937 | Â MBErrorCode result; |
|---|
| 1938 | |
|---|
| 1939 | Â MBRange new_sets; |
|---|
| 1940 |  int num_sets; |
|---|
| 1941 |  UNPACK_INT(buff_ptr, num_sets); |
|---|
| 1942 | |
|---|
| 1943 |  if (!num_sets) return MB_SUCCESS; |
|---|
| 1944 | Â Â Â Â Â |
|---|
| 1945 | Â std::vector<MBEntityHandle>Â members; |
|---|
| 1946 |  int num_ents; |
|---|
| 1947 |  std::vector<unsigned int> options_vec(num_sets); |
|---|
| 1948 | Â Â Â // option value |
|---|
| 1949 |  if (num_sets) |
|---|
| 1950 |   UNPACK_VOID(buff_ptr, &options_vec[0], num_sets*sizeof(unsigned int)); |
|---|
| 1951 | |
|---|
| 1952 | Â Â // create sets |
|---|
| 1953 |  int i; |
|---|
| 1954 | Â MBRange::const_iterator rit; |
|---|
| 1955 |  for (i = 0; i < num_sets; i++) { |
|---|
| 1956 | Â Â |
|---|
| 1957 | Â Â Â // create the set |
|---|
| 1958 | Â Â MBEntityHandle set_handle; |
|---|
| 1959 |   result = mbImpl->create_meshset(options_vec[i], set_handle); |
|---|
| 1960 | Â Â RRA("Failed to create set in unpack."); |
|---|
| 1961 | |
|---|
| 1962 | Â Â // make sure new sets handles are monotonically increasing |
|---|
| 1963 | Â Â assert(set_handle >Â *new_sets.rbegin()); |
|---|
| 1964 | |
|---|
| 1965 | Â Â new_sets.insert(set_handle); |
|---|
| 1966 | Â } |
|---|
| 1967 | |
|---|
| 1968 | Â entities.merge(new_sets); |
|---|
| 1969 | Â |
|---|
| 1970 |  for (rit = new_sets.begin(), i = 0; rit != new_sets.end(); rit++, i++) { |
|---|
| 1971 |   if (options_vec[i] & MESHSET_SET) { |
|---|
| 1972 | Â Â Â Â // unpack entities as a range |
|---|
| 1973 |    MBRange set_range, tmp_range; |
|---|
| 1974 |    UNPACK_RANGE(buff_ptr, tmp_range); |
|---|
| 1975 |    result = get_local_handles(tmp_range, set_range, entities);   |
|---|
| 1976 | Â Â Â RRA("Failed to get local handles for unordered set contents."); |
|---|
| 1977 |    result = mbImpl->add_entities(*rit, set_range); |
|---|
| 1978 | Â Â Â RRA("Failed to add ents to unordered set in unpack."); |
|---|
| 1979 | Â Â } |
|---|
| 1980 |   else if (options_vec[i] & MESHSET_ORDERED) { |
|---|
| 1981 | Â Â Â Â // unpack entities as vector, with length |
|---|
| 1982 |    UNPACK_INT(buff_ptr, num_ents); |
|---|
| 1983 | Â Â Â members.resize(num_ents); |
|---|
| 1984 |    if (num_ents) UNPACK_EH(buff_ptr, &members[0], num_ents); |
|---|
| 1985 |    result = get_local_handles(&members[0], num_ents, entities); |
|---|
| 1986 | Â Â Â RRA("Failed to get local handles for ordered set contents."); |
|---|
| 1987 |    result = mbImpl->add_entities(*rit, &members[0], num_ents); |
|---|
| 1988 | Â Â Â RRA("Failed to add ents to ordered set in unpack."); |
|---|
| 1989 | Â Â } |
|---|
| 1990 | Â } |
|---|
| 1991 | |
|---|
| 1992 | Â std::vector<int>Â num_pch(2*new_sets.size()); |
|---|
| 1993 | Â std::vector<int>::iterator vit; |
|---|
| 1994 |  int tot_pch = 0; |
|---|
| 1995 |  for (vit = num_pch.begin(); vit != num_pch.end(); vit++) { |
|---|
| 1996 |   UNPACK_INT(buff_ptr, *vit); |
|---|
| 1997 | Â Â tot_pch +=Â *vit; |
|---|
| 1998 | Â } |
|---|
| 1999 | Â |
|---|
| 2000 | Â members.resize(tot_pch); |
|---|
| 2001 |  UNPACK_EH(buff_ptr, &members[0], tot_pch); |
|---|
| 2002 |  result = get_local_handles(&members[0], tot_pch, entities); |
|---|
| 2003 | Â RRA("Couldn't get local handle for parent/child sets."); |
|---|
| 2004 | |
|---|
| 2005 |  int num = 0; |
|---|
| 2006 | Â MBEntityHandle *mem_ptr =Â &members[0]; |
|---|
| 2007 |  for (rit = new_sets.begin(); rit != new_sets.end(); rit++) { |
|---|
| 2008 | Â Â Â // unpack parents/children |
|---|
| 2009 |   int num_par = num_pch[num++], num_child = num_pch[num++]; |
|---|
| 2010 |   if (num_par+num_child) { |
|---|
| 2011 |    for (i = 0; i < num_par; i++) { |
|---|
| 2012 | Â Â Â Â assert(0Â !=Â mem_ptr[i]); |
|---|
| 2013 |     result = mbImpl->add_parent_meshset(*rit, mem_ptr[i]); |
|---|
| 2014 | Â Â Â Â RRA("Failed to add parent to set in unpack."); |
|---|
| 2015 | Â Â Â } |
|---|
| 2016 | Â Â Â mem_ptr +=Â num_par; |
|---|
| 2017 |    for (i = 0; i < num_child; i++) { |
|---|
| 2018 | Â Â Â Â assert(0Â !=Â mem_ptr[i]); |
|---|
| 2019 |     result = mbImpl->add_child_meshset(*rit, mem_ptr[i]); |
|---|
| 2020 | Â Â Â Â RRA("Failed to add child to set in unpack."); |
|---|
| 2021 | Â Â Â } |
|---|
| 2022 | Â Â Â mem_ptr +=Â num_child; |
|---|
| 2023 | Â Â } |
|---|
| 2024 | Â } |
|---|
| 2025 | |
|---|
| 2026 | Â Â // unpack source handles |
|---|
| 2027 | Â MBRange dum_range; |
|---|
| 2028 |  if (store_remote_handles && !new_sets.empty()) { |
|---|
| 2029 |   UNPACK_RANGE(buff_ptr, dum_range); |
|---|
| 2030 |   result = set_remote_data(new_sets, dum_range, from_proc); |
|---|
| 2031 | Â Â RRA("Couldn't set sharing data for sets"); |
|---|
| 2032 | Â } |
|---|
| 2033 | |
|---|
| 2034 |  if (debug_packing) std::cerr << std::endl << "Done unpacking sets." << std::endl; |
|---|
| 2035 | |
|---|
| 2036 |  return MB_SUCCESS; |
|---|
| 2037 | } |
|---|
| 2038 | |
|---|
| 2039 | MBErrorCode MBParallelComm::pack_adjacencies(MBRange &entities, |
|---|
| 2040 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange::const_iterator &start_rit, |
|---|
| 2041 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &whole_range, |
|---|
| 2042 |                        unsigned char *&buff_ptr, |
|---|
| 2043 |                        int &count, |
|---|
| 2044 |                        const bool just_count, |
|---|
| 2045 |                        const bool store_handles, |
|---|
| 2046 |                        const int to_proc) |
|---|
| 2047 | { |
|---|
| 2048 |  return MB_FAILURE; |
|---|
| 2049 | } |
|---|
| 2050 | |
|---|
| 2051 | MBErrorCode MBParallelComm::unpack_adjacencies(unsigned char *&buff_ptr, |
|---|
| 2052 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &entities, |
|---|
| 2053 |                         const bool store_handles, |
|---|
| 2054 |                         const int from_proc) |
|---|
| 2055 | { |
|---|
| 2056 |  return MB_FAILURE; |
|---|
| 2057 | } |
|---|
| 2058 | |
|---|
| 2059 | MBErrorCode MBParallelComm::pack_tags(MBRange &entities, |
|---|
| 2060 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange::const_iterator &start_rit, |
|---|
| 2061 |                    const MBRange &whole_range, |
|---|
| 2062 |                    unsigned char *&buff_ptr, |
|---|
| 2063 |                    int &count, |
|---|
| 2064 |                    const bool just_count, |
|---|
| 2065 |                    const bool store_remote_handles, |
|---|
| 2066 |                    const int to_proc, |
|---|
| 2067 |                    const std::vector<MBTag> &all_tags, |
|---|
| 2068 |                    const std::vector<MBRange> &tag_ranges) |
|---|
| 2069 | { |
|---|
| 2070 | Â Â // get all the tags |
|---|
| 2071 | |
|---|
| 2072 | Â MBErrorCode result; |
|---|
| 2073 | Â std::vector<MBTag>::const_iterator tag_it; |
|---|
| 2074 | Â std::vector<MBRange>::const_iterator rit; |
|---|
| 2075 | |
|---|
| 2076 |  if (just_count) { |
|---|
| 2077 | Â Â |
|---|
| 2078 |   for (tag_it = all_tags.begin(), rit = tag_ranges.begin(); |
|---|
| 2079 |      tag_it != all_tags.end(); tag_it++, rit++) { |
|---|
| 2080 | |
|---|
| 2081 |    result = packed_tag_size( *tag_it, *rit, count ); |
|---|
| 2082 |    if (MB_SUCCESS != result) |
|---|
| 2083 |     return result; |
|---|
| 2084 | Â Â } |
|---|
| 2085 | Â Â |
|---|
| 2086 | Â Â Â // number of tags |
|---|
| 2087 | Â Â count +=Â sizeof(int); |
|---|
| 2088 | Â } |
|---|
| 2089 | |
|---|
| 2090 |  else { |
|---|
| 2091 | |
|---|
| 2092 |   PACK_INT(buff_ptr, all_tags.size()); |
|---|
| 2093 | Â Â count +=Â sizeof(int); |
|---|
| 2094 | Â Â |
|---|
| 2095 |   for (tag_it = all_tags.begin(), rit = tag_ranges.begin(); |
|---|
| 2096 |      tag_it != all_tags.end(); tag_it++, rit++) { |
|---|
| 2097 | Â Â Â Â Â |
|---|
| 2098 | Â Â |
|---|
| 2099 |    result = pack_tag( *tag_it, *tag_it, *rit, whole_range, buff_ptr, |
|---|
| 2100 |              count, store_remote_handles, to_proc ); |
|---|
| 2101 |    if (MB_SUCCESS != result) |
|---|
| 2102 |     return result; |
|---|
| 2103 | Â Â } |
|---|
| 2104 | Â } |
|---|
| 2105 | Â |
|---|
| 2106 |  if (debug_packing) std::cerr << std::endl << "Done packing tags." << std::endl; |
|---|
| 2107 | |
|---|
| 2108 |  return MB_SUCCESS; |
|---|
| 2109 | } |
|---|
| 2110 | Â Â Â Â Â |
|---|
| 2111 | |
|---|
| 2112 | MBErrorCode MBParallelComm::packed_tag_size(Â MBTag tag, |
|---|
| 2113 |                        const MBRange &tagged_entities, |
|---|
| 2114 |                        int &count ) |
|---|
| 2115 | { |
|---|
| 2116 | Â Â // for dense tags, compute size assuming all entities have that tag |
|---|
| 2117 | Â Â // for sparse tags, get number of entities w/ that tag to compute size |
|---|
| 2118 | |
|---|
| 2119 | Â std::vector<int>Â var_len_sizes; |
|---|
| 2120 |  std::vector<const void*> var_len_values; |
|---|
| 2121 | Â Â |
|---|
| 2122 |  const TagInfo *tinfo = tagServer->get_tag_info(tag); |
|---|
| 2123 | Â Â // default value |
|---|
| 2124 | Â count +=Â sizeof(int); |
|---|
| 2125 |  if (NULL != tinfo->default_value()) |
|---|
| 2126 | Â Â count +=Â tinfo->default_value_size(); |
|---|
| 2127 | |
|---|
| 2128 | Â Â // size, type, data type |
|---|
| 2129 | Â count +=Â 3*sizeof(int); |
|---|
| 2130 | |
|---|
| 2131 | Â Â // name |
|---|
| 2132 | Â count +=Â sizeof(int); |
|---|
| 2133 | Â count +=Â tinfo->get_name().size(); |
|---|
| 2134 | |
|---|
| 2135 | Â Â // range of tag |
|---|
| 2136 | Â count +=Â sizeof(int)Â +Â tagged_entities.size()Â *Â sizeof(MBEntityHandle); |
|---|
| 2137 | |
|---|
| 2138 |  if (tinfo->get_size() == MB_VARIABLE_LENGTH) { |
|---|
| 2139 |   const int num_ent = tagged_entities.size(); |
|---|
| 2140 | Â Â Â // send a tag size for each entity |
|---|
| 2141 | Â Â count +=Â num_ent *Â sizeof(int); |
|---|
| 2142 | Â Â Â // send tag data for each entity |
|---|
| 2143 | Â Â var_len_sizes.resize(Â num_ent ); |
|---|
| 2144 | Â Â var_len_values.resize(Â num_ent ); |
|---|
| 2145 | Â Â MBErrorCode result =Â tagServer->get_data(Â tag, |
|---|
| 2146 |                        tagged_entities, |
|---|
| 2147 |                        &var_len_values[0], |
|---|
| 2148 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &var_len_sizes[0]Â ); |
|---|
| 2149 | Â Â RRA("Failed to get lenghts of variable-length tag values."); |
|---|
| 2150 |   count += std::accumulate( var_len_sizes.begin(), var_len_sizes.end(), 0 ); |
|---|
| 2151 | Â } |
|---|
| 2152 |  else { |
|---|
| 2153 | Â Â Â // tag data values for range or vector |
|---|
| 2154 | Â Â count +=Â tagged_entities.size()Â *Â tinfo->get_size(); |
|---|
| 2155 | Â } |
|---|
| 2156 | Â |
|---|
| 2157 |  return MB_SUCCESS; |
|---|
| 2158 | } |
|---|
| 2159 | |
|---|
| 2160 | |
|---|
| 2161 | MBErrorCode MBParallelComm::pack_tag(Â MBTag src_tag, |
|---|
| 2162 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBTag dst_tag, |
|---|
| 2163 |                    const MBRange &tagged_entites, |
|---|
| 2164 |                    const MBRange &whole_range, |
|---|
| 2165 |                    unsigned char *&buff_ptr, |
|---|
| 2166 |                    int &count, |
|---|
| 2167 |                    const bool store_remote_handles, |
|---|
| 2168 |                    const int to_proc ) |
|---|
| 2169 | { |
|---|
| 2170 |  unsigned char *orig_buff_ptr = buff_ptr; |
|---|
| 2171 | Â MBErrorCode result; |
|---|
| 2172 | Â std::vector<int>Â var_len_sizes; |
|---|
| 2173 |  std::vector<const void*> var_len_values; |
|---|
| 2174 | |
|---|
| 2175 |  const TagInfo* tinfo = tagServer->get_tag_info(src_tag); |
|---|
| 2176 |  if (!tinfo) |
|---|
| 2177 |   return MB_TAG_NOT_FOUND; |
|---|
| 2178 | Â Â |
|---|
| 2179 |  const TagInfo* dst_tinfo; |
|---|
| 2180 |  if (src_tag == dst_tag) { |
|---|
| 2181 | Â Â dst_tinfo =Â tinfo; |
|---|
| 2182 | Â } |
|---|
| 2183 |  else { |
|---|
| 2184 | Â Â dst_tinfo =Â tagServer->get_tag_info(dst_tag); |
|---|
| 2185 |   if (!dst_tinfo) |
|---|
| 2186 |    return MB_TAG_NOT_FOUND; |
|---|
| 2187 |   if (dst_tinfo->get_size() != tinfo->get_size()) |
|---|
| 2188 |    return MB_TYPE_OUT_OF_RANGE; |
|---|
| 2189 |   if (dst_tinfo->get_data_type() != tinfo->get_data_type() && |
|---|
| 2190 | Â Â Â Â dst_tinfo->get_data_type()Â !=Â MB_TYPE_OPAQUE && |
|---|
| 2191 | Â Â Â Â Â Â tinfo->get_data_type()Â !=Â MB_TYPE_OPAQUE) |
|---|
| 2192 |    return MB_TYPE_OUT_OF_RANGE; |
|---|
| 2193 | Â } |
|---|
| 2194 | Â Â |
|---|
| 2195 | Â Â |
|---|
| 2196 | |
|---|
| 2197 | Â Â // size, type, data type |
|---|
| 2198 |  PACK_INT(buff_ptr, tinfo->get_size()); |
|---|
| 2199 | Â MBTagType this_type; |
|---|
| 2200 |  result = mbImpl->tag_get_type(dst_tag, this_type); |
|---|
| 2201 |  PACK_INT(buff_ptr, (int)this_type); |
|---|
| 2202 |  PACK_INT(buff_ptr, (int)(tinfo->get_data_type())); |
|---|
| 2203 | |
|---|
| 2204 | Â Â // default value |
|---|
| 2205 |  if (NULL == tinfo->default_value()) { |
|---|
| 2206 |   PACK_INT(buff_ptr, 0); |
|---|
| 2207 | Â } |
|---|
| 2208 |  else { |
|---|
| 2209 |   PACK_BYTES(buff_ptr, tinfo->default_value(), tinfo->default_value_size()); |
|---|
| 2210 | Â } |
|---|
| 2211 | |
|---|
| 2212 | Â Â // name |
|---|
| 2213 |  PACK_BYTES(buff_ptr, dst_tinfo->get_name().c_str(), dst_tinfo->get_name().size()); |
|---|
| 2214 | |
|---|
| 2215 | #ifdef DEBUG_PACKING |
|---|
| 2216 | std::cerr <<Â "Packing tag \""Â <<Â tinfo->get_name()Â <<Â "\""; |
|---|
| 2217 | if (tinfo != dst_tinfo) |
|---|
| 2218 | Â std::cerr <<Â " (as tag \""Â <<Â dst_tinfo->get_name()Â <<Â "\")"; |
|---|
| 2219 | std::cerr <<Â std::endl; |
|---|
| 2220 | #endif  |
|---|
| 2221 | Â Â // pack entities |
|---|
| 2222 |  PACK_INT(buff_ptr, tagged_entites.size()); |
|---|
| 2223 | Â result =Â get_remote_handles(store_remote_handles, |
|---|
| 2224 |                tagged_entites, (MBEntityHandle*)buff_ptr, to_proc, |
|---|
| 2225 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â whole_range); |
|---|
| 2226 | #ifdef DEBUG_PACKING |
|---|
| 2227 |  if (MB_SUCCESS != result) { |
|---|
| 2228 | Â Â std::cerr <<Â "Trouble getting remote handles for tagged entities:"Â <<Â std::endl; |
|---|
| 2229 | Â Â tagged_entites.print("Â "); |
|---|
| 2230 | Â } |
|---|
| 2231 | #else |
|---|
| 2232 | Â RRA("Trouble getting remote handles for tagged entities."); |
|---|
| 2233 | #endif |
|---|
| 2234 | |
|---|
| 2235 | Â buff_ptr +=Â tagged_entites.size()Â *Â sizeof(MBEntityHandle); |
|---|
| 2236 | |
|---|
| 2237 |  const size_t num_ent = tagged_entites.size(); |
|---|
| 2238 |  if (tinfo->get_size() == MB_VARIABLE_LENGTH) { |
|---|
| 2239 |   var_len_sizes.resize( num_ent, 0 ); |
|---|
| 2240 |   var_len_values.resize( num_ent, 0 ); |
|---|
| 2241 |   result = mbImpl->tag_get_data(src_tag, tagged_entites, &var_len_values[0], |
|---|
| 2242 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &var_len_sizes[0]Â ); |
|---|
| 2243 | Â Â RRA("Failed to get variable-length tag data in pack_tags."); |
|---|
| 2244 |   PACK_INTS(buff_ptr, &var_len_sizes[0], num_ent); |
|---|
| 2245 |   for (unsigned int i = 0; i < num_ent; ++i) |
|---|
| 2246 |    PACK_VOID(buff_ptr, var_len_values[i], var_len_sizes[i]); |
|---|
| 2247 | Â } |
|---|
| 2248 |  else { |
|---|
| 2249 |   result = mbImpl->tag_get_data(src_tag, tagged_entites, buff_ptr); |
|---|
| 2250 | Â Â RRA("Failed to get tag data in pack_tags."); |
|---|
| 2251 | Â Â buff_ptr +=Â num_ent *Â tinfo->get_size(); |
|---|
| 2252 |   PC(num_ent*tinfo->get_size(), " void"); |
|---|
| 2253 | Â } |
|---|
| 2254 | |
|---|
| 2255 | Â count +=Â buff_ptr -Â orig_buff_ptr; |
|---|
| 2256 | |
|---|
| 2257 |  return MB_SUCCESS; |
|---|
| 2258 | } |
|---|
| 2259 | |
|---|
| 2260 | MBErrorCode MBParallelComm::get_tag_send_list( const MBRange& whole_range, |
|---|
| 2261 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â std::vector<MBTag>&Â all_tags, |
|---|
| 2262 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â std::vector<MBRange>&Â tag_ranges ) |
|---|
| 2263 | { |
|---|
| 2264 | Â std::vector<MBTag>Â tmp_tags; |
|---|
| 2265 | Â MBErrorCode result =Â tagServer->get_tags(tmp_tags); |
|---|
| 2266 | Â RRA("Failed to get tags in pack_tags."); |
|---|
| 2267 | |
|---|
| 2268 | Â std::vector<MBTag>::iterator tag_it; |
|---|
| 2269 |  for (tag_it = tmp_tags.begin(); tag_it != tmp_tags.end(); tag_it++) { |
|---|
| 2270 | Â Â std::string tag_name; |
|---|
| 2271 |   result = mbImpl->tag_get_name(*tag_it, tag_name); |
|---|
| 2272 |   if (tag_name.c_str()[0] == '_' && tag_name.c_str()[1] == '_') |
|---|
| 2273 | Â Â Â continue; |
|---|
| 2274 | |
|---|
| 2275 | Â Â MBRange tmp_range; |
|---|
| 2276 |   result = tagServer->get_entities(*tag_it, tmp_range); |
|---|
| 2277 | Â Â RRA("Failed to get entities for tag in pack_tags."); |
|---|
| 2278 | Â Â tmp_range =Â tmp_range.intersect(whole_range); |
|---|
| 2279 | |
|---|
| 2280 |   if (tmp_range.empty()) continue; |
|---|
| 2281 | Â Â Â Â |
|---|
| 2282 | Â Â Â // ok, we'll be sending this tag |
|---|
| 2283 | Â Â all_tags.push_back(Â *tag_it ); |
|---|
| 2284 | Â Â tag_ranges.push_back(Â MBRange()Â ); |
|---|
| 2285 | Â Â tag_ranges.back().swap(Â tmp_range ); |
|---|
| 2286 | Â } |
|---|
| 2287 | Â |
|---|
| 2288 |  return MB_SUCCESS; |
|---|
| 2289 | } |
|---|
| 2290 | |
|---|
| 2291 | |
|---|
| 2292 | |
|---|
| 2293 | MBErrorCode MBParallelComm::unpack_tags(unsigned char *&buff_ptr, |
|---|
| 2294 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &entities, |
|---|
| 2295 |                     const bool store_remote_handles, |
|---|
| 2296 |                     const int from_proc) |
|---|
| 2297 | { |
|---|
| 2298 | Â Â // tags |
|---|
| 2299 | Â Â // get all the tags |
|---|
| 2300 | Â Â // for dense tags, compute size assuming all entities have that tag |
|---|
| 2301 | Â Â // for sparse tags, get number of entities w/ that tag to compute size |
|---|
| 2302 | |
|---|
| 2303 | Â MBErrorCode result; |
|---|
| 2304 | Â |
|---|
| 2305 |  int num_tags; |
|---|
| 2306 |  UNPACK_INT(buff_ptr, num_tags); |
|---|
| 2307 | Â std::vector<MBEntityHandle>Â tag_ents; |
|---|
| 2308 |  std::vector<const void*> var_len_vals; |
|---|
| 2309 | Â std::vector<int>Â var_lengths; |
|---|
| 2310 | |
|---|
| 2311 |  for (int i = 0; i < num_tags; i++) { |
|---|
| 2312 | Â Â |
|---|
| 2313 | Â Â Â Â // tag handle |
|---|
| 2314 | Â Â MBTag tag_handle; |
|---|
| 2315 | |
|---|
| 2316 | Â Â Â // size, data type |
|---|
| 2317 |   int tag_size, tag_data_type, tag_type; |
|---|
| 2318 |   UNPACK_INT(buff_ptr, tag_size); |
|---|
| 2319 |   UNPACK_INT(buff_ptr, tag_type); |
|---|
| 2320 |   UNPACK_INT(buff_ptr, tag_data_type); |
|---|
| 2321 | Â Â Â |
|---|
| 2322 | Â Â Â // default value |
|---|
| 2323 |   int def_val_size; |
|---|
| 2324 |   UNPACK_INT(buff_ptr, def_val_size); |
|---|
| 2325 |   void *def_val_ptr = NULL; |
|---|
| 2326 |   if (def_val_size) { |
|---|
| 2327 | Â Â Â def_val_ptr =Â buff_ptr; |
|---|
| 2328 | Â Â Â buff_ptr +=Â def_val_size; |
|---|
| 2329 |    UPC(tag_size, " void"); |
|---|
| 2330 | Â Â } |
|---|
| 2331 | Â Â |
|---|
| 2332 | Â Â Â // name |
|---|
| 2333 |   int name_len; |
|---|
| 2334 |   UNPACK_INT(buff_ptr, name_len); |
|---|
| 2335 |   std::string tag_name( reinterpret_cast<char*>(buff_ptr), name_len ); |
|---|
| 2336 | Â Â buff_ptr +=Â name_len; |
|---|
| 2337 |   UPC(64, " chars"); |
|---|
| 2338 | #ifdef DEBUG_PACKING |
|---|
| 2339 | Â Â std::cerr <<Â "Unpacking tag "Â <<Â tag_name <<Â std::endl; |
|---|
| 2340 | #endif  |
|---|
| 2341 | |
|---|
| 2342 | Â Â Â // create the tag |
|---|
| 2343 |   if (tag_size == MB_VARIABLE_LENGTH) |
|---|
| 2344 |    result = mbImpl->tag_create_variable_length( tag_name.c_str(), (MBTagType)tag_type, |
|---|
| 2345 |                           (MBDataType)tag_data_type, tag_handle, |
|---|
| 2346 |                           def_val_ptr, def_val_size ); |
|---|
| 2347 | Â Â else |
|---|
| 2348 |    result = mbImpl->tag_create(tag_name.c_str(), tag_size, (MBTagType) tag_type, |
|---|
| 2349 |                  (MBDataType) tag_data_type, tag_handle, |
|---|
| 2350 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â def_val_ptr); |
|---|
| 2351 |   if (MB_ALREADY_ALLOCATED == result) { |
|---|
| 2352 | Â Â Â Â // already allocated tag, check to make sure it's the same size, type, etc. |
|---|
| 2353 |    const TagInfo *tag_info = tagServer->get_tag_info(tag_name.c_str()); |
|---|
| 2354 | Â Â Â MBTagType this_type; |
|---|
| 2355 |    result = mbImpl->tag_get_type(tag_handle, this_type); |
|---|
| 2356 |    if (tag_size != tag_info->get_size() || |
|---|
| 2357 | Â Â Â Â Â tag_type !=Â this_type || |
|---|
| 2358 | Â Â Â Â Â tag_data_type !=Â tag_info->get_data_type()Â || |
|---|
| 2359 | Â Â Â Â Â (def_val_ptr &&Â !tag_info->default_value())Â || |
|---|
| 2360 | Â Â Â Â Â (!def_val_ptr &&Â tag_info->default_value()))Â { |
|---|
| 2361 | Â Â Â Â RRA("Didn't get correct tag info when unpacking tag."); |
|---|
| 2362 | Â Â Â } |
|---|
| 2363 | Â Â } |
|---|
| 2364 |   else if (MB_SUCCESS != result) return result; |
|---|
| 2365 | |
|---|
| 2366 | Â Â Â // go through handle vec (in buffer) and convert to local handles in-place |
|---|
| 2367 |   int num_ents; |
|---|
| 2368 |   UNPACK_INT(buff_ptr, num_ents); |
|---|
| 2369 | Â Â MBEntityHandle *handle_vec =Â (MBEntityHandle*)buff_ptr; |
|---|
| 2370 |   result = get_local_handles(handle_vec, num_ents, entities); |
|---|
| 2371 | Â Â RRA("Failed to get local handles for tagged entities."); |
|---|
| 2372 | Â Â buff_ptr +=Â num_ents *Â sizeof(MBEntityHandle); |
|---|
| 2373 | |
|---|
| 2374 | Â Â Â // if it's a handle type, also convert tag vals in-place in buffer |
|---|
| 2375 |   if (MB_TYPE_HANDLE == tag_type) { |
|---|
| 2376 | Â Â Â MBEntityHandle *val_vec =Â (MBEntityHandle*)buff_ptr; |
|---|
| 2377 |    result = get_local_handles(val_vec, num_ents, entities); |
|---|
| 2378 | Â Â Â RRA("Failed to get local handles for tag vals."); |
|---|
| 2379 | Â Â } |
|---|
| 2380 | |
|---|
| 2381 |   if (tag_size == MB_VARIABLE_LENGTH) { |
|---|
| 2382 |     // Be careful of alignment here. If the integers are aligned |
|---|
| 2383 |     // in the buffer, we can use them directly. Otherwise we must |
|---|
| 2384 | Â Â Â Â // copy them. |
|---|
| 2385 |    const int* size_arr; |
|---|
| 2386 |    if (((size_t)buff_ptr)%4) { |
|---|
| 2387 | Â Â Â Â var_lengths.resize(Â num_ents ); |
|---|
| 2388 |     memcpy( &var_lengths[0], buff_ptr, num_ents*sizeof(int) ); |
|---|
| 2389 | Â Â Â Â size_arr =Â &var_lengths[0]; |
|---|
| 2390 | Â Â Â } |
|---|
| 2391 |    else { |
|---|
| 2392 |     size_arr = reinterpret_cast<const int*>(buff_ptr); |
|---|
| 2393 | Â Â Â } |
|---|
| 2394 | Â Â Â buff_ptr +=Â sizeof(int)Â *Â num_ents; |
|---|
| 2395 |    UPC(sizeof(int) * num_ents, " void"); |
|---|
| 2396 | Â Â Â |
|---|
| 2397 | Â Â Â Â // get pointers into buffer for each tag value |
|---|
| 2398 | Â Â Â var_len_vals.resize(num_ents); |
|---|
| 2399 |    for (std::vector<MBEntityHandle>::size_type i = 0; |
|---|
| 2400 | Â Â Â Â Â Â i <Â (std::vector<MBEntityHandle>::size_type)Â num_ents;Â ++i)Â { |
|---|
| 2401 | Â Â Â Â var_len_vals[i]Â =Â buff_ptr; |
|---|
| 2402 | Â Â Â Â buff_ptr +=Â size_arr[i]; |
|---|
| 2403 |     UPC(size_arr[i], " void"); |
|---|
| 2404 | Â Â Â } |
|---|
| 2405 |    result = mbImpl->tag_set_data( tag_handle, handle_vec, num_ents, |
|---|
| 2406 |                    &var_len_vals[0], size_arr ); |
|---|
| 2407 | Â Â Â RRA("Trouble setting tag data when unpacking variable-length tag."); |
|---|
| 2408 | Â Â } |
|---|
| 2409 |   else { |
|---|
| 2410 |    result = mbImpl->tag_set_data(tag_handle, handle_vec, |
|---|
| 2411 |                   num_ents, buff_ptr); |
|---|
| 2412 | Â Â Â RRA("Trouble setting range-based tag data when unpacking tag."); |
|---|
| 2413 | Â Â Â buff_ptr +=Â num_ents *Â tag_size; |
|---|
| 2414 |    UPC(num_ents * tag_size, " void"); |
|---|
| 2415 | Â Â } |
|---|
| 2416 | Â } |
|---|
| 2417 | Â |
|---|
| 2418 |  if (debug_packing) std::cerr << std::endl << "Done unpacking tags." << std::endl; |
|---|
| 2419 | |
|---|
| 2420 |  return MB_SUCCESS; |
|---|
| 2421 | } |
|---|
| 2422 | |
|---|
| 2423 | MBErrorCode MBParallelComm::resolve_shared_ents(MBEntityHandle this_set, |
|---|
| 2424 |                         int resolve_dim, |
|---|
| 2425 |                         int shared_dim) |
|---|
| 2426 | { |
|---|
| 2427 | Â MBErrorCode result; |
|---|
| 2428 | Â MBRange proc_ents; |
|---|
| 2429 | Â Â Â // get the entities in the partition sets |
|---|
| 2430 |  for (MBRange::iterator rit = partitionSets.begin(); rit != partitionSets.end(); rit++) { |
|---|
| 2431 | Â Â MBRange tmp_ents; |
|---|
| 2432 |   result = mbImpl->get_entities_by_handle(*rit, tmp_ents, true); |
|---|
| 2433 |   if (MB_SUCCESS != result) return result; |
|---|
| 2434 | Â Â proc_ents.merge(tmp_ents); |
|---|
| 2435 | Â } |
|---|
| 2436 | |
|---|
| 2437 | Â Â // resolve dim is maximal dim of entities in proc_ents |
|---|
| 2438 |  if (-1 == resolve_dim) { |
|---|
| 2439 | Â Â resolve_dim =Â mbImpl->dimension_from_handle(*proc_ents.rbegin());Â |
|---|
| 2440 | Â Â RRA("Couldn't get dimension."); |
|---|
| 2441 | Â Â |
|---|
| 2442 | Â } |
|---|
| 2443 | |
|---|
| 2444 | Â Â // proc_ents should all be of same dimension |
|---|
| 2445 |  if (resolve_dim > shared_dim && |
|---|
| 2446 | Â Â Â mbImpl->dimension_from_handle(*proc_ents.rbegin())Â != |
|---|
| 2447 | Â Â Â mbImpl->dimension_from_handle(*proc_ents.begin()))Â { |
|---|
| 2448 | Â Â MBRange::iterator lower =Â proc_ents.lower_bound(MBCN::TypeDimensionMap[0].first), |
|---|
| 2449 | Â Â Â upper =Â proc_ents.upper_bound(MBCN::TypeDimensionMap[resolve_dim-1].second); |
|---|
| 2450 |   proc_ents.erase(lower, upper); |
|---|
| 2451 | Â } |
|---|
| 2452 | Â |
|---|
| 2453 | Â Â // must call even if we don't have any entities, to make sure |
|---|
| 2454 | Â Â // collective comm'n works |
|---|
| 2455 |  return resolve_shared_ents(this_set, proc_ents, resolve_dim, shared_dim); |
|---|
| 2456 | } |
|---|
| 2457 | Â |
|---|
| 2458 | MBErrorCode MBParallelComm::resolve_shared_ents(MBEntityHandle this_set, |
|---|
| 2459 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBRange &proc_ents, |
|---|
| 2460 |                         int resolve_dim, |
|---|
| 2461 |                         int shared_dim) |
|---|
| 2462 | { |
|---|
| 2463 | Â MBErrorCode result; |
|---|
| 2464 |  if (debug) std::cerr << "Resolving shared entities." << std::endl; |
|---|
| 2465 | |
|---|
| 2466 |  if (-1 == shared_dim) { |
|---|
| 2467 |   if (0 == resolve_dim) { |
|---|
| 2468 | Â Â Â result =Â mbImpl->get_dimension(shared_dim);Â |
|---|
| 2469 | Â Â Â RRA("Couldn't get dimension."); |
|---|
| 2470 | Â Â } |
|---|
| 2471 |   else shared_dim = mbImpl->dimension_from_handle(*proc_ents.begin())-1; |
|---|
| 2472 | Â } |
|---|
| 2473 | Â assert(shared_dim >=Â 0Â &&Â resolve_dim >=Â 0); |
|---|
| 2474 | Â |
|---|
| 2475 | Â Â // get the skin entities by dimension |
|---|
| 2476 | Â MBRange skin_ents[4]; |
|---|
| 2477 | Â std::vector<int>Â gid_data; |
|---|
| 2478 | Â std::vector<MBEntityHandle>Â handle_vec; |
|---|
| 2479 |  int skin_dim; |
|---|
| 2480 | |
|---|
| 2481 | Â Â // get the entities to be skinned |
|---|
| 2482 |  if (resolve_dim < shared_dim) { |
|---|
| 2483 | Â Â Â // for vertex-based partition, it's the elements adj to the vertices |
|---|
| 2484 |   result = mbImpl->get_adjacencies(proc_ents, shared_dim, |
|---|
| 2485 |                    false, skin_ents[resolve_dim], |
|---|
| 2486 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBInterface::UNION); |
|---|
| 2487 | Â Â RRA("Failed getting skinned entities."); |
|---|
| 2488 | Â Â skin_dim =Â shared_dim-1; |
|---|
| 2489 | Â } |
|---|
| 2490 |  else { |
|---|
| 2491 | Â Â Â // for element-based partition, it's just the elements |
|---|
| 2492 | Â Â skin_ents[resolve_dim]Â =Â proc_ents; |
|---|
| 2493 | Â Â skin_dim =Â resolve_dim-1; |
|---|
| 2494 | Â } |
|---|
| 2495 | |
|---|
| 2496 | Â Â // find the skin |
|---|
| 2497 | Â MBSkinner skinner(mbImpl); |
|---|
| 2498 |  result = skinner.find_skin(skin_ents[skin_dim+1], skin_ents[skin_dim], |
|---|
| 2499 |                skin_ents[skin_dim], true); |
|---|
| 2500 | Â RRA("Failed to find skin."); |
|---|
| 2501 |  if (debug) std::cerr << "Found skin, now resolving." << std::endl; |
|---|
| 2502 | |
|---|
| 2503 | Â Â // get entities adjacent to skin ents from shared_dim down to |
|---|
| 2504 | Â Â // zero; don't create them if they don't exist already |
|---|
| 2505 |  for (int this_dim = skin_dim-1; this_dim >= 0; this_dim--) { |
|---|
| 2506 |   result = mbImpl->get_adjacencies(skin_ents[skin_dim], this_dim, |
|---|
| 2507 |                    false, skin_ents[this_dim], |
|---|
| 2508 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBInterface::UNION); |
|---|
| 2509 | Â Â RRA("Failed getting skin adjacencies."); |
|---|
| 2510 | Â } |
|---|
| 2511 | |
|---|
| 2512 | Â Â // resolve shared vertices first |
|---|
| 2513 | |
|---|
| 2514 | Â Â // global id tag |
|---|
| 2515 |  MBTag gid_tag; int def_val = -1; |
|---|
| 2516 |  result = mbImpl->tag_create(GLOBAL_ID_TAG_NAME, sizeof(int), |
|---|
| 2517 |                MB_TAG_DENSE, MB_TYPE_INTEGER, gid_tag, |
|---|
| 2518 |                &def_val, true); |
|---|
| 2519 |  if (MB_FAILURE == result) return result; |
|---|
| 2520 | |
|---|
| 2521 |  else if (MB_ALREADY_ALLOCATED != result) { |
|---|
| 2522 | Â Â Â // just created it, so we need global ids |
|---|
| 2523 |   result = assign_global_ids(0, skin_dim+1); |
|---|
| 2524 | Â Â RRA("Failed assigning global ids."); |
|---|
| 2525 | Â } |
|---|
| 2526 | |
|---|
| 2527 | Â Â // store index in temp tag; reuse gid_data |
|---|
| 2528 | Â gid_data.resize(2*skin_ents[0].size()); |
|---|
| 2529 |  int idx = 0; |
|---|
| 2530 |  for (MBRange::iterator rit = skin_ents[0].begin(); |
|---|
| 2531 | Â Â Â Â rit !=Â skin_ents[0].end();Â rit++)Â |
|---|
| 2532 |   gid_data[idx] = idx, idx++; |
|---|
| 2533 | Â MBTag idx_tag; |
|---|
| 2534 |  result = mbImpl->tag_create("__idx_tag", sizeof(int), MB_TAG_DENSE, |
|---|
| 2535 |                MB_TYPE_INTEGER, idx_tag, &def_val, true); |
|---|
| 2536 |  if (MB_SUCCESS != result && MB_ALREADY_ALLOCATED != result) return result; |
|---|
| 2537 |  result = mbImpl->tag_set_data(idx_tag, skin_ents[0], &gid_data[0]); |
|---|
| 2538 | Â RRA("Couldn't assign index tag."); |
|---|
| 2539 | |
|---|
| 2540 | Â Â // get gids for skin ents in a vector, to pass to gs |
|---|
| 2541 |  result = mbImpl->tag_get_data(gid_tag, skin_ents[0], &gid_data[0]); |
|---|
| 2542 | Â RRA("Couldn't get gid tag for skin vertices."); |
|---|
| 2543 | |
|---|
| 2544 | Â Â // put handles in vector for passing to gs setup |
|---|
| 2545 |  std::copy(skin_ents[0].begin(), skin_ents[0].end(), |
|---|
| 2546 | Â Â Â Â Â Â std::back_inserter(handle_vec)); |
|---|
| 2547 | Â |
|---|
| 2548 | Â Â // get a crystal router |
|---|
| 2549 | Â crystal_data *cd =Â procConfig.crystal_router(); |
|---|
| 2550 | Â |
|---|
| 2551 | Â Â // get total number of entities; will overshoot highest global id, but |
|---|
| 2552 | Â Â // that's ok |
|---|
| 2553 |  int num_total = 0, num_local; |
|---|
| 2554 |  result = mbImpl->get_number_entities_by_dimension(0, 0, num_local); |
|---|
| 2555 |  if (MB_SUCCESS != result) return result; |
|---|
| 2556 |  int failure = MPI_Allreduce(&num_local, &num_total, 1, |
|---|
| 2557 |                MPI_INT, MPI_SUM, procConfig.proc_comm()); |
|---|
| 2558 |  if (failure) { |
|---|
| 2559 | Â Â result =Â MB_FAILURE; |
|---|
| 2560 | Â Â RRA("Allreduce for total number of shared ents failed."); |
|---|
| 2561 | Â } |
|---|
| 2562 | Â |
|---|
| 2563 | Â Â // call gather-scatter to get shared ids & procs |
|---|
| 2564 | Â gs_data *gsd; |
|---|
| 2565 | Â assert(sizeof(ulong_)Â ==Â sizeof(MBEntityHandle)); |
|---|
| 2566 |  if (sizeof(int) != sizeof(ulong_)) { |
|---|
| 2567 | Â Â std::vector<long>Â lgid_data(gid_data.size()); |
|---|
| 2568 |   std::copy(gid_data.begin(), gid_data.end(), lgid_data.begin()); |
|---|
| 2569 |   gsd = gs_data_setup(skin_ents[0].size(), &lgid_data[0], |
|---|
| 2570 |             (ulong_*)&handle_vec[0], 2, 1, 1, cd); |
|---|
| 2571 | Â } |
|---|
| 2572 |  else { |
|---|
| 2573 |   gsd = gs_data_setup(skin_ents[0].size(), (long*)&gid_data[0], |
|---|
| 2574 |             (ulong_*)&handle_vec[0], 2, 1, 1, cd); |
|---|
| 2575 | Â } |
|---|
| 2576 | Â |
|---|
| 2577 |  if (NULL == gsd) { |
|---|
| 2578 | Â Â result =Â MB_FAILURE; |
|---|
| 2579 | Â Â RRA("Couldn't create gs data."); |
|---|
| 2580 | Â } |
|---|
| 2581 | |
|---|
| 2582 | Â Â // get shared proc tags |
|---|
| 2583 |  MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag; |
|---|
| 2584 |  result = get_shared_proc_tags(sharedp_tag, sharedps_tag, |
|---|
| 2585 |                 sharedh_tag, sharedhs_tag, pstatus_tag); |
|---|
| 2586 | Â RRA("Couldn't get shared proc tags."); |
|---|
| 2587 | Â |
|---|
| 2588 | Â Â // load shared verts into a tuple, then sort by index |
|---|
| 2589 | Â tuple_list shared_verts; |
|---|
| 2590 |  tuple_list_init_max(&shared_verts, 2, 0, 1, 0, |
|---|
| 2591 | Â Â Â Â Â Â Â Â Â Â Â skin_ents[0].size()*(MAX_SHARING_PROCS+1)); |
|---|
| 2592 |  unsigned int i = 0, j = 0; |
|---|
| 2593 |  for (unsigned int p = 0; p < gsd->nlinfo->np; p++) |
|---|
| 2594 |   for (unsigned int np = 0; np < gsd->nlinfo->nshared[p]; np++) { |
|---|
| 2595 | Â Â Â shared_verts.vi[i++]Â =Â gsd->nlinfo->sh_ind[j]; |
|---|
| 2596 | Â Â Â shared_verts.vi[i++]Â =Â gsd->nlinfo->target[p]; |
|---|
| 2597 | Â Â Â shared_verts.vul[j]Â =Â gsd->nlinfo->ulabels[j]; |
|---|
| 2598 | Â Â Â j++; |
|---|
| 2599 | Â Â Â shared_verts.n++; |
|---|
| 2600 | Â Â } |
|---|
| 2601 | Â |
|---|
| 2602 |  int max_size = skin_ents[0].size()*(MAX_SHARING_PROCS+1); |
|---|
| 2603 | Â std::vector<int>Â sort_buffer(max_size); |
|---|
| 2604 |  tuple_list_sort(&shared_verts, 0,(buffer*)&sort_buffer[0]); |
|---|
| 2605 | |
|---|
| 2606 | Â Â // set sharing procs and handles tags on skin ents |
|---|
| 2607 |  int maxp = -1; |
|---|
| 2608 | Â std::vector<int>Â sharing_procs(MAX_SHARING_PROCS); |
|---|
| 2609 |  std::fill(sharing_procs.begin(), sharing_procs.end(), maxp); |
|---|
| 2610 | Â j =Â 0;Â i =Â 0; |
|---|
| 2611 | |
|---|
| 2612 | Â Â // get ents shared by 1 or n procs |
|---|
| 2613 |  std::map<std::vector<int>, MBRange> proc_nranges; |
|---|
| 2614 | Â MBRange proc_verts; |
|---|
| 2615 |  result = mbImpl->get_adjacencies(proc_ents, 0, false, proc_verts, |
|---|
| 2616 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBInterface::UNION); |
|---|
| 2617 | Â RRA("Couldn't get proc_verts."); |
|---|
| 2618 | Â |
|---|
| 2619 |  result = tag_shared_verts(shared_verts, skin_ents, |
|---|
| 2620 |               proc_nranges, proc_verts); |
|---|
| 2621 | Â RRA("Trouble tagging shared verts."); |
|---|
| 2622 | |
|---|
| 2623 | Â Â // get entities shared by 1 or n procs |
|---|
| 2624 |  result = tag_shared_ents(resolve_dim, shared_dim, shared_verts, skin_ents, |
|---|
| 2625 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â proc_nranges); |
|---|
| 2626 | Â RRA("Trouble tagging shared entities."); |
|---|
| 2627 | |
|---|
| 2628 |  if (debug) { |
|---|
| 2629 |   for (std::map<std::vector<int>, MBRange>::const_iterator mit = proc_nranges.begin(); |
|---|
| 2630 | Â Â Â Â Â mit !=Â proc_nranges.end();Â mit++)Â { |
|---|
| 2631 | Â Â Â std::cout <<Â "Iface: "; |
|---|
| 2632 |    for (std::vector<int>::const_iterator vit = (mit->first).begin(); |
|---|
| 2633 | Â Â Â Â Â Â vit !=Â (mit->first).end();Â vit++)Â std::cout <<Â " "Â <<Â *vit; |
|---|
| 2634 | Â Â Â std::cout <<Â std::endl; |
|---|
| 2635 | Â Â } |
|---|
| 2636 | Â } |
|---|
| 2637 | Â |
|---|
| 2638 | Â Â // create the sets for each interface; store them as tags on |
|---|
| 2639 | Â Â // the interface instance |
|---|
| 2640 | Â MBRange iface_sets; |
|---|
| 2641 |  result = create_interface_sets(proc_nranges, this_set, resolve_dim, shared_dim); |
|---|
| 2642 | Â RRA("Trouble creating iface sets."); |
|---|
| 2643 | |
|---|
| 2644 | Â Â // resolve shared entity remote handles; implemented in ghost cell exchange |
|---|
| 2645 | Â Â // code because it's so similar |
|---|
| 2646 |  result = exchange_ghost_cells(-1, -1, 0, true, true); |
|---|
| 2647 | Â RRA("Trouble resolving shared entity remote handles."); |
|---|
| 2648 | |
|---|
| 2649 | Â Â // now set the shared/interface tag on non-vertex entities on interface |
|---|
| 2650 | Â result =Â tag_iface_entities(); |
|---|
| 2651 | Â RRA("Failed to tag iface entities."); |
|---|
| 2652 | |
|---|
| 2653 | Â Â // now build parent/child links for interface sets |
|---|
| 2654 | Â result =Â create_iface_pc_links(); |
|---|
| 2655 | Â RRA("Trouble creating interface parent/child links."); |
|---|
| 2656 | Â |
|---|
| 2657 | Â Â // done |
|---|
| 2658 |  return result; |
|---|
| 2659 | } |
|---|
| 2660 | |
|---|
| 2661 | MBErrorCode MBParallelComm::tag_iface_entities()Â |
|---|
| 2662 | { |
|---|
| 2663 |  MBRange all_ents, if_ents; |
|---|
| 2664 | Â MBErrorCode result; |
|---|
| 2665 |  for (MBRange::iterator if_it = interfaceSets.begin(); if_it != interfaceSets.end(); if_it++) { |
|---|
| 2666 | Â Â Â // get all ents |
|---|
| 2667 |   result = mbImpl->get_entities_by_handle(*if_it, if_ents); |
|---|
| 2668 | Â Â RRA("Trouble getting iface entities."); |
|---|
| 2669 | Â } |
|---|
| 2670 |  std::vector<unsigned char> tvals(if_ents.size()); |
|---|
| 2671 |  result = mbImpl->tag_get_data(pstatus_tag(), if_ents, &tvals[0]); |
|---|
| 2672 | Â RRA("Failed to get pstatus tag values."); |
|---|
| 2673 | Â |
|---|
| 2674 |  for (unsigned int i = 0; i < tvals.size(); i++) |
|---|
| 2675 | Â Â tvals[i]Â |=Â PSTATUS_INTERFACE; |
|---|
| 2676 | Â |
|---|
| 2677 |  result = mbImpl->tag_set_data(pstatus_tag(), if_ents, &tvals[0]); |
|---|
| 2678 | Â RRA("Failed to set pstatus tag values."); |
|---|
| 2679 | Â |
|---|
| 2680 |  return MB_SUCCESS; |
|---|
| 2681 | } |
|---|
| 2682 | |
|---|
| 2683 | MBErrorCode MBParallelComm::set_pstatus_entities(MBRange &pstatus_ents, |
|---|
| 2684 |                          unsigned char pstatus_val, |
|---|
| 2685 |                          bool lower_dim_ents, |
|---|
| 2686 |                          bool verts_too, |
|---|
| 2687 |                          int operation) |
|---|
| 2688 | { |
|---|
| 2689 |  std::vector<unsigned char> pstatus_vals(pstatus_ents.size()); |
|---|
| 2690 |  MBRange all_ents, *range_ptr = &pstatus_ents; |
|---|
| 2691 | Â MBErrorCode result; |
|---|
| 2692 |  if (lower_dim_ents || verts_too) { |
|---|
| 2693 | Â Â all_ents =Â pstatus_ents; |
|---|
| 2694 | Â Â range_ptr =Â &all_ents; |
|---|
| 2695 |   int start_dim = (lower_dim_ents ? mbImpl->dimension_from_handle(*pstatus_ents.rbegin())-1 : 0); |
|---|
| 2696 |   for (; start_dim >= 0; start_dim--) { |
|---|
| 2697 |    result = mbImpl->get_adjacencies(all_ents, start_dim, true, all_ents, |
|---|
| 2698 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBInterface::UNION); |
|---|
| 2699 | Â Â Â RRA(" "); |
|---|
| 2700 | Â Â } |
|---|
| 2701 | Â } |
|---|
| 2702 |  if (MBInterface::UNION == operation) { |
|---|
| 2703 |   result = mbImpl->tag_get_data(pstatus_tag(), *range_ptr, &pstatus_vals[0]); |
|---|
| 2704 | Â Â RRA("Couldn't get pstatus tag value."); |
|---|
| 2705 |   for (unsigned int i = pstatus_ents.size()-1; i >= 0; i--) |
|---|
| 2706 | Â Â Â pstatus_vals[i]Â |=Â pstatus_val; |
|---|
| 2707 | Â } |
|---|
| 2708 |  else { |
|---|
| 2709 |   for (unsigned int i = pstatus_ents.size()-1; i >= 0; i--) |
|---|
| 2710 | Â Â Â pstatus_vals[i]Â =Â pstatus_val; |
|---|
| 2711 | Â } |
|---|
| 2712 |  result = mbImpl->tag_set_data(pstatus_tag(), *range_ptr, &pstatus_vals[0]); |
|---|
| 2713 | Â RRA("Couldn't set pstatus tag value."); |
|---|
| 2714 | Â |
|---|
| 2715 |  return MB_SUCCESS; |
|---|
| 2716 | } |
|---|
| 2717 | Â |
|---|
| 2718 | MBErrorCode MBParallelComm::create_interface_sets(std::map<std::vector<int>, MBRange> &proc_nranges, |
|---|
| 2719 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MBEntityHandle this_set, |
|---|
| 2720 |                          int resolve_dim, int shared_dim) |
|---|
| 2721 | { |
|---|
| 2722 |  if (proc_nranges.empty()) return MB_SUCCESS; |
|---|
| 2723 | Â |
|---|
| 2724 |  int proc_ids[MAX_SHARING_PROCS]; |
|---|
| 2725 |  MBTag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag; |
|---|
| 2726 |  MBErrorCode result = get_shared_proc_tags(sharedp_tag, sharedps_tag, |
|---|
| 2727 |                       sharedh_tag, sharedhs_tag, |
|---|
| 2728 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â pstatus_tag); |
|---|
| 2729 | Â RRA("Trouble getting shared proc tags in create_interface_sets."); |
|---|
| 2730 | Â MBRange::iterator rit; |
|---|
| 2731 | |
|---|
| 2732 | Â Â // create interface sets, tag them, and tag their contents with iface set tag |
|---|
| 2733 | Â std::vector<MBEntityHandle>Â tag_vals; |
|---|
| 2734 |  std::vector<unsigned char> pstatus; |
|---|
| 2735 |  for (std::map<std::vector<int>,MBRange>::iterator mit = proc_nranges.begin(); |
|---|
| 2736 | Â Â Â Â mit !=Â proc_nranges.end();Â mit++)Â { |
|---|
| 2737 | Â Â Â // create the set |
|---|
| 2738 | Â Â MBEntityHandle new_set; |
|---|
| 2739 |   result = mbImpl->create_meshset(MESHSET_SET, new_set); |
|---|
| 2740 | Â Â RRA("Failed to create interface set."); |
|---|
| 2741 | Â Â interfaceSets.insert(new_set); |
|---|
| 2742 | |
|---|
| 2743 | Â Â Â // add entities |
|---|
| 2744 |   result = mbImpl->add_entities(new_set, mit->second); |
|---|
| 2745 | Â Â RRA("Failed to add entities to interface set."); |
|---|
| 2746 | Â Â Â // tag set with the proc rank(s) |
|---|
| 2747 |   if (mit->first.size() == 1) |
|---|
| 2748 |    result = mbImpl->tag_set_data(sharedp_tag, &new_set, 1, |
|---|
| 2749 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &(mit->first)[0]);Â |
|---|
| 2750 |   else { |
|---|
| 2751 | Â Â Â // pad tag data out to MAX_SHARING_PROCS with -1 |
|---|
| 2752 | Â Â Â assert(Â mit->first.size()Â <=Â MAX_SHARING_PROCS ); |
|---|
| 2753 |    std::copy( mit->first.begin(), mit->first.end(), proc_ids ); |
|---|
| 2754 |    std::fill( proc_ids + mit->first.size(), proc_ids + MAX_SHARING_PROCS, -1 ); |
|---|
| 2755 |    result = mbImpl->tag_set_data(sharedps_tag, &new_set, 1, proc_ids ); |
|---|
| 2756 | Â Â } |
|---|
| 2757 | Â Â RRA("Failed to tag interface set with procs."); |
|---|
| 2758 | Â Â |
|---|
| 2759 | Â Â Â // get the owning proc, then set the pstatus tag on iface set |
|---|
| 2760 |   int min_proc = (mit->first)[0]; |
|---|
| 2761 |   unsigned char pval = (PSTATUS_SHARED | PSTATUS_INTERFACE); |
|---|
| 2762 |   if (min_proc < (int) procConfig.proc_rank()) pval |= PSTATUS_NOT_OWNED; |
|---|
| 2763 |   result = mbImpl->tag_set_data(pstatus_tag, &new_set, 1, &pval); |
|---|
| 2764 | Â Â RRA("Failed to tag interface set with pstatus."); |
|---|
| 2765 | |
|---|
| 2766 | Â Â Â // tag the entities with the same thing |
|---|
| 2767 | Â Â pstatus.clear(); |
|---|
| 2768 |   pstatus.resize(mit->second.size(), pval); |
|---|
| 2769 |   result = mbImpl->tag_set_data(pstatus_tag, mit->second, &pstatus[0]); |
|---|
| 2770 | Â Â RRA("Failed to tag interface set entities with pstatus."); |
|---|
| 2771 | Â } |
|---|
| 2772 | |
|---|
| 2773 |  return MB_SUCCESS; |
|---|
| 2774 | } |
|---|
| 2775 | |
|---|
| 2776 | MBErrorCode MBParallelComm::create_iface_pc_links()Â |
|---|
| 2777 | { |
|---|
| 2778 | Â Â // now that we've resolved the entities in the iface sets, |
|---|
| 2779 | Â Â // set parent/child links between the iface sets |
|---|
| 2780 | |
|---|
| 2781 | Â Â // first tag all entities in the iface sets |
|---|
| 2782 | Â MBTag tmp_iface_tag; |
|---|
| 2783 | Â MBEntityHandle tmp_iface_set =Â 0; |
|---|
| 2784 |  MBErrorCode result = mbImpl->tag_create("__tmp_iface", sizeof(MBEntityHandle), |
|---|
| 2785 |                      MB_TAG_DENSE, MB_TYPE_HANDLE, |
|---|
| 2786 |                      tmp_iface_tag, &tmp_iface_set); |
|---|
| 2787 |  if (MB_ALREADY_ALLOCATED != result && MB_SUCCESS != result) |
|---|
| 2788 | Â Â RRA("Failed to create temporary iface set tag."); |
|---|
| 2789 | |
|---|
| 2790 | Â MBRange iface_ents; |
|---|
| 2791 | Â std::vector<MBEntityHandle>Â tag_vals; |
|---|
| 2792 | Â MBRange::iterator rit; |
|---|
| 2793 | Â |
|---|
| 2794 |  for (rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) { |
|---|
| 2795 | Â Â Â // tag entities with interface set |
|---|
| 2796 | Â Â iface_ents.clear(); |
|---|
| 2797 |   result = mbImpl->get_entities_by_handle(*rit, iface_ents); |
|---|
| 2798 | Â Â RRA("Couldn't get entities in iface set."); |
|---|
| 2799 | Â Â |
|---|
| 2800 |   if (iface_ents.empty()) continue; |
|---|
| 2801 | Â Â |
|---|
| 2802 | Â Â tag_vals.resize(iface_ents.size()); |
|---|
| 2803 |   std::fill(tag_vals.begin(), tag_vals.end(), *rit); |
|---|
| 2804 |   result = mbImpl->tag_set_data(tmp_iface_tag, iface_ents, &tag_vals[0]); |
|---|
| 2805 | Â Â RRA("Failed to tag iface entities with interface set."); |
|---|
| 2806 | Â } |
|---|
| 2807 | Â |
|---|
| 2808 | Â Â // now go back through interface sets and add parent/child links |
|---|
| 2809 | Â MBRange tmp_ents2; |
|---|
| 2810 |  for (int d = 2; d >= 0; d--) { |
|---|
| 2811 |   for (rit = interfaceSets.begin(); rit != interfaceSets.end(); rit++) { |
|---|
| 2812 | Â Â Â Â // get entities on this interface |
|---|
| 2813 | Â Â Â iface_ents.clear(); |
|---|
| 2814 |    result = mbImpl->get_entities_by_handle(*rit, iface_ents, true); |
|---|
| 2815 | Â Â Â RRA("Couldn't get entities by dimension."); |
|---|
| 2816 |    if (iface_ents.empty() || |
|---|
| 2817 | Â Â Â Â Â mbImpl->dimension_from_handle(*iface_ents.rbegin())Â !=Â d)Â continue; |
|---|
| 2818 | |
|---|
| 2819 | Â Â Â Â // get higher-dimensional entities and their interface sets |
|---|
| 2820 |    result = mbImpl->get_adjacencies(&(*iface_ents.begin()), 1, d+1, |
|---|
| 2821 |                     false, tmp_ents2); |
|---|
| 2822 | Â Â Â RRA("Couldn't get adjacencies for interface sets."); |
|---|
| 2823 | Â Â Â tag_vals.resize(tmp_ents2.size()); |
|---|
| 2824 |    result = mbImpl->tag_get_data(tmp_iface_tag, tmp_ents2, &tag_vals[0]); |
|---|
| 2825 | Â Â Â RRA("Couldn't get iface set tag for interface sets."); |
|---|
| 2826 | Â Â Â |
|---|
| 2827 | Â Â Â Â // go through and for any on interface make it a parent |
|---|
| 2828 | Â Â Â MBEntityHandle last_set =Â 0; |
|---|
| 2829 |    for (unsigned int i = 0; i < tag_vals.size(); i++) { |
|---|
| 2830 |     if (tag_vals[i] && tag_vals[i] != last_set) { |
|---|
| 2831 |      result = mbImpl->add_parent_child(tag_vals[i], *rit); |
|---|
| 2832 | Â Â Â Â Â RRA("Couldn't add parent/child link for interface set."); |
|---|
| 2833 | Â Â Â Â Â last_set =Â tag_vals[i]; |
|---|
| 2834 | Â Â Â Â } |
|---|
| 2835 | Â Â Â } |
|---|
| 2836 | Â Â } |
|---|
| 2837 | Â } |
|---|
| 2838 | Â |
|---|
| 2839 | Â Â // delete the temporary tag |
|---|
| 2840 | Â result =Â mbImpl->tag_delete(tmp_iface_tag); |
|---|
| 2841 | Â RRA("Couldn't delete tmp iface tag."); |
|---|
| 2842 | |
|---|
| 2843 |  return MB_SUCCESS; |
|---|
| 2844 | } |
|---|
| 2845 | |
|---|
| 2846 | MBErrorCode MBParallelComm::tag_shared_ents(int resolve_dim, |
|---|
| 2847 | Â Â Â Â Â |
|---|