Zoltan2  Version of the Day
GidLookupHelper.cpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 // @HEADER
46 // ***********************************************************************
47 // Zoltan2: Sandia Partitioning Ordering & Coloring Library
48 // ***********************************************************************
49 // @HEADER
50 //
51 // Test the GidLookupHelper class.
52 
54 
55 using namespace std;
56 using Teuchos::RCP;
57 using Teuchos::rcp;
58 using Teuchos::ArrayRCP;
59 using Teuchos::Comm;
60 
61 int main(int argc, char *argv[])
62 {
63  Teuchos::GlobalMPISession session(&argc, &argv);
64  RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
65  int rank = comm->getRank();
66  RCP<const Zoltan2::Environment> env = rcp(new Zoltan2::Environment);
67  ArrayRCP<int> idx;
68 
69  if (rank == 0){
70  int *buf = new int [10];
71  for (int i=0; i < 10; i++)
72  buf[i] = (i+1)*10;
73 
74  // ten distinct gids
75  cout << endl << "10 distinct int gids" << endl;
76  ArrayRCP<const int> intGids = Teuchos::arcp(buf, 0, 10, true);
77  Zoltan2::GidLookupHelper<int, int> glhInt(env, intGids);
78  cout << "Lookup:" << endl;
79  for (int i=0; i < 10; i++){
80  cout << "Gid: " << buf[i] << " idx: " << glhInt.lookup(buf[i]) << endl;
81  }
82 
83  // ten gids with duplicates
84  cout << endl << "10 int gids with duplicates" << endl;
85  for (int i=0; i < 5; i++)
86  buf[i] = buf[i+5] = i;
87  Zoltan2::GidLookupHelper<int, int> glhIntDup(env, intGids);
88  cout << "Lookup:" << endl;
89  for (int i=0; i < 10; i++){
90  cout << "Gid: " << buf[i] << " idx: " << glhIntDup.lookup(buf[i]) << endl;
91  }
92 
93  // string gids
94  cout << endl << "4 string gids" << endl;
95  string *sbuf = new string [4];
96  sbuf[0] = string("gid number 0");
97  sbuf[1] = string("gid number 1");
98  sbuf[2] = string("gid number 2");
99  sbuf[3] = string("gid number 3");
100  ArrayRCP<const string> sGids = Teuchos::arcp(sbuf, 0, 4, true);
101  Zoltan2::GidLookupHelper<string, int> glhString(env, sGids);
102  cout << "Lookup:" << endl;
103  for (int i=0; i < 4; i++){
104  cout << "Gid: " << sbuf[i] << " idx: " << glhString.lookup(sbuf[i]) << endl;
105  }
106 
107  // string gids with duplicates
108  cout << endl << "4 string gids with a duplicate" << endl;
109  sbuf[3] = string("gid number 0");
110  Zoltan2::GidLookupHelper<string, int> glhStringDup(env, sGids);
111  cout << "Lookup:" << endl;
112  for (int i=0; i < 4; i++){
113  cout << "Gid: " << sbuf[i] << " idx: " << glhStringDup.lookup(sbuf[i]) << endl;
114  }
115 
116  cout << "PASS" << endl;
117  }
118 }
Defines GidLookupHelper class.
lno_t lookup(const T gid) const
the index of the global id in the gidList passed into the constructor.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
int main(int argc, char *argv[])
A class to do GID lookups.