63#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
66#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
84 int NumProc = Map.Comm().NumProc();
86#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
87 if(Map.GlobalIndicesInt())
89 AllMinGIDs_int_ = new int[NumProc+1];
90 int MinMyGID = (int) Map.MinMyGID64();
91 Map.Comm().GatherAll(&MinMyGID, AllMinGIDs_int_, 1);
92 AllMinGIDs_int_[NumProc] = (int) (1 + Map.MaxAllGID64());
96#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
99 AllMinGIDs_LL_ = new long long[NumProc+1];
100 long long MinMyGID = Map.MinMyGID64();
101 Map.Comm().GatherAll(&MinMyGID, AllMinGIDs_LL_, 1);
102 AllMinGIDs_LL_[NumProc] = 1 + Map.MaxAllGID64();
106 throw "Epetra_BasicDirectory::Epetra_BasicDirectory: Unknown map index type";
114 if(Map.GlobalIndicesInt())
115#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
121 throw "Epetra_BasicDirectory::Epetra_BasicDirectory: ERROR, GlobalIndicesInt but no API for it.";
123 else if(Map.GlobalIndicesLongLong())
124#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
128 Generate<long long>(Map);
130 throw "Epetra_BasicDirectory::Epetra_BasicDirectory: ERROR, GlobalIndicesLongLong but no API for it.";
149#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
152#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
161 ProcList_ = new int[Dir_NumMyElements];
162 for (int i=0; i<Dir_NumMyElements; i++) ProcList_[i] = Directory.ProcList_[i];
165 LocalIndexList_ = new int[Dir_NumMyElements];
166 for (int i=0; i<Dir_NumMyElements; i++) LocalIndexList_[i] = Directory.LocalIndexList_[i];
169 SizeList_ = new int[Dir_NumMyElements];
170 for (int i=0; i<Dir_NumMyElements; i++) SizeList_[i] = Directory.SizeList_[i];
172#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
174 int NumProc = DirectoryMap_->Comm().NumProc();
175 AllMinGIDs_int_ = new int[NumProc+1];
176 for (int i=0; i<NumProc+1; i++) AllMinGIDs_int_[i] = Directory.AllMinGIDs_int_[i];
179#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
181 int NumProc = DirectoryMap_->Comm().NumProc();
182 AllMinGIDs_LL_ = new long long[NumProc+1];
183 for (int i=0; i<NumProc+1; i++) AllMinGIDs_LL_[i] = Directory.AllMinGIDs_LL_[i];
188 int num = Directory.numProcLists_;
189 ProcListLens_ = new int[num];
190 ProcListLists_ = new int*[num];
193 for(int i=0; i<num; ++i) {
194 int len = Directory.ProcListLens_[i];
195 ProcListLens_[i] = len;
198 ProcListLists_[i] = new int[len];
199 const int* dir_list = Directory.ProcListLists_[i];
200 for(int j=0; j<len; ++j) {
201 ProcListLists_[i][j] = dir_list[j];
204 else ProcListLists_[i] = 0;
208 entryOnMultipleProcs_ = Directory.entryOnMultipleProcs_;
280 int_type Dir_NumGlobalElements = MaxAllGID - MinAllGID + 1;
291 if (Dir_NumMyElements>0) {
292 ProcList_ =
new int[ Dir_NumMyElements ];
298 for (i=0; i<Dir_NumMyElements; i++) {
311 int * send_procs = 0;
312 if (Map_NumMyElements>0) send_procs =
new int[Map_NumMyElements];
313 int_type * Map_MyGlobalElements = 0;
314#if !defined(EPETRA_NO_32BIT_GLOBAL_INDICES) || !defined(EPETRA_NO_64BIT_GLOBAL_INDICES)
318 Map_MyGlobalElements,
322 bool det_flag =
true;
330 if (Map_NumMyElements>0)
delete [] send_procs;
332 int * export_elements = 0;
333 char * c_import_elements = 0;
334 int * import_elements = 0;
335 int len_import_elements = 0;
336 int * ElementSizeList = 0;
338 int packetSize = (int) (
sizeof(int_type) + 2*
sizeof(
int))/
sizeof(int);
341 if (Map_NumMyElements>0) {
343 export_elements =
new int[ packetSize * Map_NumMyElements ];
344 int * ptr = export_elements;
345 for( i = 0; i < Map_NumMyElements; i++ )
347 *(int_type*)ptr = Map_MyGlobalElements[i];
348 ptr +=
sizeof(int_type)/
sizeof(
int);
359 packetSize * (
int)
sizeof(
int ),
361 c_import_elements ));
363 import_elements =
reinterpret_cast<int *
>(c_import_elements);
368 int * ptr = import_elements;
369 for( i = 0; i < num_recvs; i++ )
372 ptr +=
sizeof(int_type)/
sizeof(
int);
374 assert(curr_LID !=-1);
396 int localval, globalval;
401 if (len_import_elements!=0)
delete [] c_import_elements;
402 if (export_elements!=0)
delete [] export_elements;
420 const int NumEntries,
421 const int_type * GlobalEntries,
425 bool high_rank_sharing_procs)
const
440 int * ElementSizeList = 0;
442 if (ConstantElementSize)
446 for (i=0; i<NumEntries; i++) {
447 int LID = Map.
LID(GlobalEntries[i]);
453 else Procs[i] = MyPID;
456 if (LocalEntries!=0) LocalEntries[i] = LID;
460 if (ConstantElementSize)
461 EntrySizes[i] = ElementSize;
463 EntrySizes[i] = ElementSizeList[LID];
477 for (i=0; i<NumEntries; i++) {
480 int_type GID = GlobalEntries[i];
481 if (GID<MinAllGID) ierr = 1;
482 else if (GID>MaxAllGID) ierr = 1;
489 while (Proc1 >= 0 && Proc1< NumProc) {
490 if (AllMinGIDs_ptr[Proc1]<=GID) {
491 if (GID <AllMinGIDs_ptr[Proc1+1]) {
501 LID = (int) (GID - AllMinGIDs_ptr[Proc]);
505 if (LocalEntries!=0) LocalEntries[i] = LID;
510 for (i=0; i<NumEntries; i++) EntrySizes[i] = ElementSize;
519 int_type * Size_send_gids = 0;
520 int * Size_send_procs = 0;
524 Size_num_sends, Size_send_gids, Size_send_procs ));
526 int * Size_exports = 0;
527 char * c_Size_imports = 0;
528 int * Size_imports = 0;
529 int packetSize = (int) (
sizeof(int_type) +
sizeof(
int))/
sizeof(int);
530 if (Size_num_sends>0) {
531 Size_exports =
new int[ packetSize * Size_num_sends ];
532 for( i = 0; i < Size_num_sends; i++ )
534 int_type Size_curr_GID = Size_send_gids[i];
535 int Size_curr_LID = Map.
LID(Size_curr_GID);
536 assert(Size_curr_LID!=-1);
537 *(int_type*)(Size_exports + packetSize*i) = Size_curr_GID;
538 int Size_curr_size = ElementSizeList[Size_curr_LID];
539 *(Size_exports + packetSize*i + (packetSize - 1)) = Size_curr_size;
543 int len_Size_imports = 0;
545 packetSize * (
int)
sizeof(
int ),
548 Size_imports =
reinterpret_cast<int*
>(c_Size_imports);
550 for( i = 0; i < NumEntries; i++ )
555 int_type Size_curr_GID = *(int_type*)(Size_imports + packetSize*i);
556 for( j = 0; j < NumEntries; j++ )
557 if( Size_curr_GID == GlobalEntries[j] )
559 EntrySizes[j] = *(Size_imports + packetSize*i + (packetSize - 1));
567 if( Size_send_gids != 0 )
delete [] Size_send_gids;
568 if( Size_send_procs != 0 )
delete [] Size_send_procs;
570 if( len_Size_imports != 0 )
delete [] c_Size_imports;
571 if( Size_exports != 0 )
delete [] Size_exports;
582 int PacketSize = (int) (
sizeof(int_type) +
sizeof(
int))/
sizeof(int);
583 bool DoSizes =
false;
587 for (i=0; i<NumEntries; i++) EntrySizes[i] = ElementSize;
595 bool DoLIDs = (LocalEntries!=0);
596 if (DoLIDs) PacketSize++;
603 if (NumEntries>0) dir_procs =
new int[ NumEntries ];
605#if !defined(EPETRA_NO_32BIT_GLOBAL_INDICES) || !defined(EPETRA_NO_64BIT_GLOBAL_INDICES)
607 DirectoryMap_->RemoteIDList(NumEntries, GlobalEntries, dir_procs, 0);
612 {
for( i = 0; i < NumEntries; ++i )
613 if( dir_procs[i] == -1 )
616 if (DoLIDs) LocalEntries[i] = -1;
621 int_type * send_gids = 0;
622 int * send_procs = 0;
625 num_sends, send_gids, send_procs));
627 if (NumEntries>0)
delete [] dir_procs;
632 char * c_imports = 0;
636 exports =
new int[ PacketSize * num_sends ];
638 for( i = 0; i < num_sends; i++ )
640 int_type curr_GID = send_gids[i];
641 *(int_type*)ptr = curr_GID;
642 ptr +=
sizeof(int_type)/
sizeof(
int);
644 assert(curr_LID!=-1);
645 if (high_rank_sharing_procs==
false) {
667 if (DoSizes) *ptr++ =
SizeList_[curr_LID];
671 int NumRecv = NumEntries - NumMissing;
673 PacketSize * (
int)
sizeof(
int ),
676 imports =
reinterpret_cast<int*
>(c_imports);
681 int* sortedGE_int =
new int[NumEntries*(1 +
sizeof(int_type)/
sizeof(int))];
682 int* offsets = sortedGE_int+NumEntries*
sizeof(int_type)/
sizeof(
int);
683 int_type* sortedGE =
reinterpret_cast<int_type*
>(sortedGE_int);
685 for(i=0; i<NumEntries; ++i) {
689 std::memcpy(sortedGE, GlobalEntries, NumEntries*
sizeof(int_type));
691 Utils.
Sort(
true, NumEntries, sortedGE, 0, 0, 1, &offsets, 0, 0);
696 for( i = 0; i < NumRecv; i++ ) {
697 int_type theCurrentLID = *(int_type*)ptr;
698 ptr +=
sizeof(int_type)/
sizeof(
int);
701 Procs[offsets[j]] = *ptr++;
702 if (DoLIDs) LocalEntries[offsets[j]] = *ptr++;
703 if (DoSizes) EntrySizes[offsets[j]] = *ptr++;
707 delete [] sortedGE_int;
709 if( send_gids )
delete [] send_gids;
710 if( send_procs )
delete [] send_procs;
712 if( len_imports )
delete [] c_imports;
713 if( exports )
delete [] exports;
static void EPETRA_LIB_DLL_EXPORT Sort(bool SortAscending, int NumKeys, T *Keys, int NumDoubleCompanions, double **DoubleCompanions, int NumIntCompanions, int **IntCompanions, int NumLongLongCompanions, long long **LongLongCompanions)
Epetra_Util Sort Routine (Shell sort)