PEXSI
 All Classes Namespaces Files Functions Variables Typedefs Pages
SuperLUGrid_impl.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012 The Regents of the University of California,
3  through Lawrence Berkeley National Laboratory.
4 
5 Authors: Mathias Jacquelin and Lin Lin
6 
7 This file is part of PEXSI. All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11 
12 (1) Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
14 (2) Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 (3) Neither the name of the University of California, Lawrence Berkeley
18 National Laboratory, U.S. Dept. of Energy nor the names of its contributors may
19 be used to endorse or promote products derived from this software without
20 specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 You are under no obligation whatsoever to provide any bug fixes, patches, or
34 upgrades to the features, functionality or performance of the source code
35 ("Enhancements") to anyone; however, if you choose to make your Enhancements
36 available either publicly, or directly to Lawrence Berkeley National
37 Laboratory, without imposing a separate written license agreement for such
38 Enhancements, then you hereby grant the following license: a non-exclusive,
39 royalty-free perpetual license to install, use, modify, prepare derivative
40 works, incorporate into other computer software, distribute, and sublicense
41 such enhancements or derivative works thereof, in binary and source code form.
42  */
46 #ifndef _PEXSI_SUPERLUGRID_IMPL_HPP_
47 #define _PEXSI_SUPERLUGRID_IMPL_HPP_
48 
49 namespace PEXSI{
50 
51 
52 
53 
54 
55 
56  inline SuperLUGrid<Real>::SuperLUGrid ( MPI_Comm comm, Int nprow, Int npcol )
57  {
58 #ifndef _RELEASE_
59  PushCallStack("SuperLUGrid::SuperLUGrid");
60 #endif
61  ptrData = new RealGridData;
62  if( ptrData == NULL ){
63 #ifdef USE_ABORT
64  abort();
65 #endif
66  throw std::runtime_error( "SuperLUGrid cannot be allocated." );
67  }
68  ptrData->GridInit(comm, nprow, npcol);
69 
70 #ifndef _RELEASE_
71  PopCallStack();
72 #endif
73 
74  return ;
75  } // ----- end of method SuperLUGrid::SuperLUGrid -----
76 
77  inline SuperLUGrid<Real>::~SuperLUGrid ( )
78  {
79 #ifndef _RELEASE_
80  PushCallStack("SuperLUGrid::~SuperLUGrid");
81 #endif
82  // NOTE (07/21/2013): Since superlu_gridinit gets a copy of the
83  // communicator, it is legal to call superlu_gridexit even if
84  // grid->comm is a copy of MPI_COMM_WORLD.
85 
86  ptrData->GridExit();
87 
88  delete ptrData;
89 
90 #ifndef _RELEASE_
91  PopCallStack();
92 #endif
93  return ;
94  } // ----- end of method SuperLUGrid::~SuperLUGrid -----
95 
96 
97 
98 
99 
100 
101  inline SuperLUGrid<Real>::SuperLUGrid(const SuperLUGrid<Real> & g)
102  {
103 #ifndef _RELEASE_
104  PushCallStack("SuperLUGrid::SuperLUGrid");
105 #endif
106 
107  if(g.ptrData == NULL){
108  throw std::runtime_error( "Original SuperLUGrid not allocated." );
109  }
110 
111  ptrData = new RealGridData(*g.ptrData);
112  if( ptrData == NULL ){
113 #ifdef USE_ABORT
114  abort();
115 #endif
116  throw std::runtime_error( "SuperLUGrid cannot be allocated." );
117  }
118 
119 #ifndef _RELEASE_
120  PopCallStack();
121 #endif
122 
123  return ;
124  } // ----- end of method SuperLUGrid::SuperLUGrid -----
125 
126  inline SuperLUGrid<Real> & SuperLUGrid<Real>::operator = (const SuperLUGrid<Real> & g){
127 
128  if(&g!=this){
129  if(this->ptrData!=NULL){
130  ptrData->GridExit();
131  delete ptrData;
132  }
133 
134  if(g.ptrData == NULL){
135  throw std::runtime_error( "Original SuperLUGrid not allocated." );
136  }
137  else{
138  ptrData = new RealGridData(*g.ptrData);
139  if( ptrData == NULL ){
140  throw std::runtime_error( "SuperLUGrid cannot be allocated." );
141  }
142  }
143  }
144 
145  return *this;
146  }
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158  inline SuperLUGrid<Complex>::SuperLUGrid ( MPI_Comm comm, Int nprow, Int npcol )
159  {
160 #ifndef _RELEASE_
161  PushCallStack("SuperLUGrid::SuperLUGrid");
162 #endif
163  ptrData = new ComplexGridData;
164  if( ptrData == NULL ){
165 #ifdef USE_ABORT
166  abort();
167 #endif
168  throw std::runtime_error( "SuperLUGrid cannot be allocated." );
169  }
170  ptrData->GridInit(comm, nprow, npcol);
171 
172 #ifndef _RELEASE_
173  PopCallStack();
174 #endif
175 
176  return ;
177  } // ----- end of method SuperLUGrid::SuperLUGrid -----
178 
179 
180  inline SuperLUGrid<Complex>::~SuperLUGrid ( )
181  {
182 #ifndef _RELEASE_
183  PushCallStack("SuperLUGrid::~SuperLUGrid");
184 #endif
185  // NOTE (07/21/2013): Since superlu_gridinit gets a copy of the
186  // communicator, it is legal to call superlu_gridexit even if
187  // grid->comm is a copy of MPI_COMM_WORLD.
188 
189  ptrData->GridExit();
190 
191  delete ptrData;
192 
193 #ifndef _RELEASE_
194  PopCallStack();
195 #endif
196  return ;
197  } // ----- end of method SuperLUGrid::~SuperLUGrid -----
198 
199 
200  inline SuperLUGrid<Complex>::SuperLUGrid(const SuperLUGrid<Complex> & g)
201  {
202 #ifndef _RELEASE_
203  PushCallStack("SuperLUGrid::SuperLUGrid");
204 #endif
205 
206  if(g.ptrData == NULL){
207  throw std::runtime_error( "Original SuperLUGrid not allocated." );
208  }
209 
210  ptrData = new ComplexGridData(*g.ptrData);
211  if( ptrData == NULL ){
212 #ifdef USE_ABORT
213  abort();
214 #endif
215  throw std::runtime_error( "SuperLUGrid cannot be allocated." );
216  }
217 
218 #ifndef _RELEASE_
219  PopCallStack();
220 #endif
221 
222  return ;
223  } // ----- end of method SuperLUGrid::SuperLUGrid -----
224 
225  inline SuperLUGrid<Complex> & SuperLUGrid<Complex>::operator = (const SuperLUGrid<Complex> & g){
226 
227  if(&g!=this){
228  if(this->ptrData!=NULL){
229  ptrData->GridExit();
230  delete ptrData;
231  }
232 
233  if(g.ptrData == NULL){
234  throw std::runtime_error( "Original SuperLUGrid not allocated." );
235  }
236  else{
237  ptrData = new ComplexGridData(*g.ptrData);
238  if( ptrData == NULL ){
239  throw std::runtime_error( "SuperLUGrid cannot be allocated." );
240  }
241  }
242  }
243 
244  return *this;
245  }
246 
247 
248 
249 
250 
251 
252 
253 
254 
255 
256 
257 }
258 
259 
260 #endif //_PEXSI_SUPERLUGRID_IMPL_HPP_
void * ptrData
SuperLUMatrix can have access to the grid information.
Definition: SuperLUGrid.hpp:101