ColPack
|
00001 /************************************************************************************ 00002 Copyright (C) 2005-2008 Assefaw H. Gebremedhin, Arijit Tarafdar, Duc Nguyen, 00003 Alex Pothen 00004 00005 This file is part of ColPack. 00006 00007 ColPack is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published 00009 by the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 ColPack is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with ColPack. If not, see <http://www.gnu.org/licenses/>. 00019 ************************************************************************************/ 00020 00021 #include "ColPackHeaders.h" 00022 00023 using namespace std; 00024 00025 namespace ColPack 00026 { 00027 00028 int JacobianRecovery1D::RecoverD2Row_RowCompressedFormat_unmanaged(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, double*** dp3_JacobianValue) { 00029 if(g==NULL) { 00030 cerr<<"g==NULL"<<endl; 00031 return _FALSE; 00032 } 00033 00034 int rowCount = g->GetRowVertexCount(); 00035 unsigned int numOfNonZeros = 0; 00036 00037 //allocate memory for *dp3_JacobianValue. The dp3_JacobianValue and uip2_JacobianSparsityPattern matrices should have the same size 00038 *dp3_JacobianValue = (double**) malloc(rowCount * sizeof(double*)); 00039 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00040 numOfNonZeros = uip2_JacobianSparsityPattern[i][0]; 00041 (*dp3_JacobianValue)[i] = (double*) malloc( (numOfNonZeros+1) * sizeof(double) ); 00042 (*dp3_JacobianValue)[i][0] = numOfNonZeros; //initialize value of the 1st entry 00043 for(int j=1; j <= numOfNonZeros; j++) (*dp3_JacobianValue)[i][j] = 0.; //initialize value of other entries 00044 } 00045 00046 return RecoverD2Row_RowCompressedFormat_usermem(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, dp3_JacobianValue); 00047 } 00048 00049 int JacobianRecovery1D::RecoverD2Row_RowCompressedFormat_usermem(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, double*** dp3_JacobianValue) { 00050 if(g==NULL) { 00051 cerr<<"g==NULL"<<endl; 00052 return _FALSE; 00053 } 00054 00055 int rowCount = g->GetRowVertexCount(); 00056 vector<int> vi_LeftVertexColors; 00057 g->GetLeftVertexColors(vi_LeftVertexColors); 00058 unsigned int numOfNonZeros = 0; 00059 00060 //allocate memory for *dp3_JacobianValue. The dp3_JacobianValue and uip2_JacobianSparsityPattern matrices should have the same size 00061 //*dp3_JacobianValue = new double*[rowCount]; 00062 //for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00063 // numOfNonZeros = uip2_JacobianSparsityPattern[i][0]; 00064 // (*dp3_JacobianValue)[i] = new double[numOfNonZeros+1]; 00065 // (*dp3_JacobianValue)[i][0] = numOfNonZeros; //initialize value of the 1st entry 00066 // for(int j=1; j <= numOfNonZeros; j++) (*dp3_JacobianValue)[i][j] = 0.; //initialize value of other entries 00067 //} 00068 00069 //Recover value of the Jacobian 00070 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00071 numOfNonZeros = uip2_JacobianSparsityPattern[i][0]; 00072 for(int j=1; j <= numOfNonZeros; j++) { 00073 (*dp3_JacobianValue)[i][j] = dp2_CompressedMatrix[vi_LeftVertexColors[i]][uip2_JacobianSparsityPattern[i][j]]; 00074 } 00075 00076 } 00077 00078 return rowCount; 00079 } 00080 00081 int JacobianRecovery1D::RecoverD2Row_RowCompressedFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, double*** dp3_JacobianValue) { 00082 int returnValue = RecoverD2Row_RowCompressedFormat_unmanaged(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, dp3_JacobianValue); 00083 00084 if(AF_available) reset(); 00085 00086 AF_available = true; 00087 i_AF_rowCount = g->GetRowVertexCount(); 00088 dp2_AF_Value = *dp3_JacobianValue; 00089 00090 return returnValue; 00091 } 00092 00093 int JacobianRecovery1D::RecoverD2Row_SparseSolversFormat_usermem(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00094 if(g==NULL) { 00095 cerr<<"g==NULL"<<endl; 00096 return _FALSE; 00097 } 00098 00099 int rowCount = g->GetRowVertexCount(); 00100 vector<int> vi_LeftVertexColors; 00101 g->GetLeftVertexColors(vi_LeftVertexColors); 00102 unsigned int numOfNonZeros = 0; 00103 00104 // Populate ip2_RowIndex and ip2_ColumnIndex 00105 //numOfNonZeros = g->GetColumnIndices(ip2_ColumnIndex); 00106 numOfNonZeros = g->GetEdgeCount();// !!!! make sure that this line is equivalent to the line above 00107 00108 //Making the array indices to start at 0 instead of 1 00109 for(unsigned int i=0; i <= (unsigned int)rowCount; i++) { 00110 (*ip2_RowIndex)[i]--; 00111 } 00112 for(unsigned int i=0; i < numOfNonZeros; i++) { 00113 (*ip2_ColumnIndex)[i]--; 00114 } 00115 00116 //Recover value of the Jacobian 00117 unsigned int numOfNonZerosInEachRow = 0; 00118 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00119 numOfNonZerosInEachRow = uip2_JacobianSparsityPattern[i][0]; 00120 for(int j=1; j <= numOfNonZerosInEachRow; j++) { 00121 (*dp2_JacobianValue)[(*ip2_RowIndex)[i]+j-1] = dp2_CompressedMatrix[vi_LeftVertexColors[i]][uip2_JacobianSparsityPattern[i][j]]; 00122 } 00123 00124 } 00125 00126 //Making the array indices to start at 1 instead of 0 to conform with theIntel MKL sparse storage scheme for the direct sparse solvers 00127 for(unsigned int i=0; i <= (unsigned int)rowCount; i++) { 00128 (*ip2_RowIndex)[i]++; 00129 } 00130 for(unsigned int i=0; i < numOfNonZeros; i++) { 00131 (*ip2_ColumnIndex)[i]++; 00132 } 00133 00134 return rowCount; 00135 } 00136 00137 int JacobianRecovery1D::RecoverD2Row_SparseSolversFormat_unmanaged(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00138 if(g==NULL) { 00139 cerr<<"g==NULL"<<endl; 00140 return _FALSE; 00141 } 00142 00143 int rowCount = g->GetRowVertexCount(); 00144 unsigned int numOfNonZeros = 0; 00145 00146 // Allocate memory and populate ip2_RowIndex and ip2_ColumnIndex 00147 g->GetRowVertices(ip2_RowIndex); 00148 numOfNonZeros = g->GetColumnIndices(ip2_ColumnIndex); 00149 00150 //Making the array indices to start at 1 instead of 0 to conform with theIntel MKL sparse storage scheme for the direct sparse solvers 00151 for(unsigned int i=0; i <= (unsigned int)rowCount; i++) { 00152 (*ip2_RowIndex)[i]++; 00153 } 00154 for(unsigned int i=0; i < numOfNonZeros; i++) { 00155 (*ip2_ColumnIndex)[i]++; 00156 } 00157 00158 (*dp2_JacobianValue) = (double*) malloc(numOfNonZeros * sizeof(double)); //allocate memory for *dp2_JacobianValue. 00159 for(unsigned int i=0; i < numOfNonZeros; i++) (*dp2_JacobianValue)[i] = 0.; //initialize value of other entries 00160 00161 return RecoverD2Row_SparseSolversFormat_usermem(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00162 } 00163 00164 int JacobianRecovery1D::RecoverD2Row_SparseSolversFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00165 int returnValue = RecoverD2Row_SparseSolversFormat_unmanaged(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00166 00167 if(SSF_available) reset(); 00168 00169 SSF_available = true; 00170 i_SSF_rowCount = g->GetRowVertexCount(); 00171 ip_SSF_RowIndex = *ip2_RowIndex; 00172 ip_SSF_ColumnIndex = *ip2_ColumnIndex; 00173 dp_SSF_Value = *dp2_JacobianValue; 00174 00175 return returnValue; 00176 } 00177 00178 int JacobianRecovery1D::RecoverD2Row_CoordinateFormat_usermem(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00179 if(g==NULL) { 00180 cerr<<"g==NULL"<<endl; 00181 return _FALSE; 00182 } 00183 00184 int rowCount = g->GetRowVertexCount(); 00185 vector<int> vi_LeftVertexColors; 00186 g->GetLeftVertexColors(vi_LeftVertexColors); 00187 00188 int numOfNonZeros; 00189 vector<int>* LeftVerticesPtr = g->GetLeftVerticesPtr(); 00190 00191 //Recover value of the Jacobian 00192 #pragma omp parallel for default(none) schedule(static) shared(rowCount,LeftVerticesPtr,dp2_JacobianValue, ip2_RowIndex, ip2_ColumnIndex, uip2_JacobianSparsityPattern, dp2_CompressedMatrix, vi_LeftVertexColors) private(numOfNonZeros) 00193 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00194 numOfNonZeros = uip2_JacobianSparsityPattern[i][0]; 00195 for(int j=1; j <= numOfNonZeros; j++) { 00196 (*dp2_JacobianValue)[(*LeftVerticesPtr)[i]+j-1] = dp2_CompressedMatrix[vi_LeftVertexColors[i]][uip2_JacobianSparsityPattern[i][j]]; 00197 (*ip2_RowIndex)[(*LeftVerticesPtr)[i]+j-1] = i; 00198 (*ip2_ColumnIndex)[(*LeftVerticesPtr)[i]+j-1] = uip2_JacobianSparsityPattern[i][j]; 00199 00200 } 00201 } 00202 /* 00203 if(numOfNonZeros_count != g->GetEdgeCount()) { 00204 cout<<"**Something fishing going on"<<endl; 00205 cout<<"numOfNonZeros_count="<<numOfNonZeros_count<<endl; 00206 cout<<"numOfNonZeros="<<g->GetEdgeCount()<<endl; 00207 } 00208 else cout<<"**Good!!!"<<endl; 00209 Pause(); 00210 //*/ 00211 00212 return (*LeftVerticesPtr)[rowCount]; 00213 } 00214 00215 int JacobianRecovery1D::RecoverD2Row_CoordinateFormat_usermem_serial(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00216 if(g==NULL) { 00217 cerr<<"g==NULL"<<endl; 00218 return _FALSE; 00219 } 00220 00221 int rowCount = g->GetRowVertexCount(); 00222 vector<int> vi_LeftVertexColors; 00223 g->GetLeftVertexColors(vi_LeftVertexColors); 00224 00225 int numOfNonZeros; 00226 00227 //Recover value of the Jacobian 00228 unsigned int numOfNonZeros_count = 0; 00229 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00230 numOfNonZeros = uip2_JacobianSparsityPattern[i][0]; 00231 for(int j=1; j <= numOfNonZeros; j++) { 00232 (*dp2_JacobianValue)[numOfNonZeros_count] = dp2_CompressedMatrix[vi_LeftVertexColors[i]][uip2_JacobianSparsityPattern[i][j]]; 00233 (*ip2_RowIndex)[numOfNonZeros_count] = i; 00234 (*ip2_ColumnIndex)[numOfNonZeros_count] = uip2_JacobianSparsityPattern[i][j]; 00235 numOfNonZeros_count++; 00236 } 00237 } 00238 /* 00239 if(numOfNonZeros_count != g->GetEdgeCount()) { 00240 cout<<"**Something fishing going on"<<endl; 00241 cout<<"numOfNonZeros_count="<<numOfNonZeros_count<<endl; 00242 cout<<"numOfNonZeros="<<g->GetEdgeCount()<<endl; 00243 } 00244 else cout<<"**Good!!!"<<endl; 00245 Pause(); 00246 //*/ 00247 00248 return numOfNonZeros_count; 00249 } 00250 00251 int JacobianRecovery1D::RecoverD2Row_CoordinateFormat_unmanaged_OMP(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00252 00253 if(g==NULL) { 00254 cerr<<"g==NULL"<<endl; 00255 return _FALSE; 00256 } 00257 00258 unsigned int numOfNonZeros = g->GetEdgeCount(); 00259 00260 // !!! test the effectiveness of this sections. Will I really get any improvement 00261 #pragma omp sections 00262 { 00263 #pragma omp section 00264 { 00265 (*ip2_RowIndex) = (unsigned int*) malloc(numOfNonZeros * sizeof(unsigned int)); 00266 } 00267 #pragma omp section 00268 { 00269 (*ip2_ColumnIndex) = (unsigned int*) malloc(numOfNonZeros * sizeof(unsigned int)); 00270 } 00271 #pragma omp section 00272 { 00273 (*dp2_JacobianValue) = (double*) malloc(numOfNonZeros * sizeof(double)); //allocate memory for *dp2_JacobianValue. 00274 } 00275 } 00276 return RecoverD2Row_CoordinateFormat_usermem(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00277 } 00278 00279 int JacobianRecovery1D::RecoverD2Row_CoordinateFormat_unmanaged(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00280 if(g==NULL) { 00281 cerr<<"g==NULL"<<endl; 00282 return _FALSE; 00283 } 00284 00285 unsigned int numOfNonZeros = g->GetEdgeCount(); 00286 00287 (*ip2_RowIndex) = (unsigned int*) malloc(numOfNonZeros * sizeof(unsigned int)); 00288 (*ip2_ColumnIndex) = (unsigned int*) malloc(numOfNonZeros * sizeof(unsigned int)); 00289 (*dp2_JacobianValue) = (double*) malloc(numOfNonZeros * sizeof(double)); //allocate memory for *dp2_JacobianValue. 00290 00291 return RecoverD2Row_CoordinateFormat_usermem_serial(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00292 } 00293 00294 int JacobianRecovery1D::RecoverD2Row_CoordinateFormat_OMP(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00295 int returnValue = RecoverD2Row_CoordinateFormat_unmanaged_OMP(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00296 00297 if(CF_available) reset(); 00298 00299 CF_available = true; 00300 i_CF_rowCount = g->GetRowVertexCount(); 00301 ip_CF_RowIndex = *ip2_RowIndex; 00302 ip_CF_ColumnIndex = *ip2_ColumnIndex; 00303 dp_CF_Value = *dp2_JacobianValue; 00304 00305 return returnValue; 00306 } 00307 00308 int JacobianRecovery1D::RecoverD2Row_CoordinateFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00309 int returnValue = RecoverD2Row_CoordinateFormat_unmanaged(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00310 00311 if(CF_available) reset(); 00312 00313 CF_available = true; 00314 i_CF_rowCount = g->GetRowVertexCount(); 00315 ip_CF_RowIndex = *ip2_RowIndex; 00316 ip_CF_ColumnIndex = *ip2_ColumnIndex; 00317 dp_CF_Value = *dp2_JacobianValue; 00318 00319 return returnValue; 00320 } 00321 00322 int JacobianRecovery1D::RecoverD2Cln_ADICFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, std::list<std::set<int> >& lsi_SparsityPattern, std::list<std::vector<double> > &lvd_NewValue) { 00323 if(g==NULL) { 00324 cerr<<"g==NULL"<<endl; 00325 return _FALSE; 00326 } 00327 00328 int rowCount = g->GetRowVertexCount(); 00329 vector<int> vi_RightVertexColors; 00330 g->GetRightVertexColors(vi_RightVertexColors); 00331 unsigned int numOfNonZeros = 0; 00332 std::list<std::set<int> >::iterator lsii_SparsityPattern = lsi_SparsityPattern.begin(); 00333 00334 //Recover value of the Jacobian 00335 //cout<<"Recover value of the Jacobian"<<endl; 00336 for(unsigned int i=0; i < (unsigned int)rowCount; lsii_SparsityPattern++, i++) { 00337 std::set<int> valset = *lsii_SparsityPattern; 00338 std::set<int>::iterator valsetiter = valset.begin(); 00339 numOfNonZeros = valset.size(); //(*lsii_SparsityPattern) is equivalent to uip2_JacobianSparsityPattern[i] 00340 std::vector<double> valuevector; 00341 valuevector.resize(numOfNonZeros); 00342 for(unsigned int j=0; j < numOfNonZeros; valsetiter++, j++) { 00343 valuevector[j] = dp2_CompressedMatrix[i][vi_RightVertexColors[*valsetiter]]; 00344 } 00345 00346 lvd_NewValue.push_back(valuevector); 00347 } 00348 00349 return rowCount; 00350 } 00351 00352 int JacobianRecovery1D::RecoverD2Cln_RowCompressedFormat_usermem(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, double*** dp3_JacobianValue) { 00353 if(g==NULL) { 00354 cerr<<"g==NULL"<<endl; 00355 return _FALSE; 00356 } 00357 00358 int rowCount = g->GetRowVertexCount(); 00359 vector<int> vi_RightVertexColors; 00360 g->GetRightVertexColors(vi_RightVertexColors); 00361 unsigned int numOfNonZeros = 0; 00362 00363 //Recover value of the Jacobian 00364 //cout<<"Recover value of the Jacobian"<<endl; 00365 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00366 numOfNonZeros = uip2_JacobianSparsityPattern[i][0]; 00367 for(unsigned int j=1; j <= numOfNonZeros; j++) { 00368 (*dp3_JacobianValue)[i][j] = dp2_CompressedMatrix[i][vi_RightVertexColors[uip2_JacobianSparsityPattern[i][j]]]; 00369 } 00370 00371 } 00372 00373 return rowCount; 00374 } 00375 00376 int JacobianRecovery1D::RecoverD2Cln_RowCompressedFormat_unmanaged(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, double*** dp3_JacobianValue) { 00377 if(g==NULL) { 00378 cerr<<"g==NULL"<<endl; 00379 return _FALSE; 00380 } 00381 00382 int rowCount = g->GetRowVertexCount(); 00383 unsigned int numOfNonZeros = 0; 00384 00385 //allocate memory for *dp3_JacobianValue. The dp3_JacobianValue and uip2_JacobianSparsityPattern matrices should have the same size 00386 //cout<<"allocate memory for *dp3_JacobianValue rowCount="<<rowCount<<endl; 00387 *dp3_JacobianValue = (double**) malloc(rowCount * sizeof(double*)); 00388 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00389 numOfNonZeros = uip2_JacobianSparsityPattern[i][0]; 00390 //printf("i=%d\tnumOfNonZeros=%d \n", i, numOfNonZeros); 00391 (*dp3_JacobianValue)[i] = (double*) malloc( (numOfNonZeros+1) * sizeof(double) ); 00392 (*dp3_JacobianValue)[i][0] = numOfNonZeros; //initialize value of the 1st entry 00393 for(unsigned int j=1; j <= numOfNonZeros; j++) (*dp3_JacobianValue)[i][j] = 0.; //initialize value of other entries 00394 } 00395 00396 return RecoverD2Cln_RowCompressedFormat_usermem(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, dp3_JacobianValue); 00397 } 00398 00399 int JacobianRecovery1D::RecoverD2Cln_RowCompressedFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, double*** dp3_JacobianValue) { 00400 int returnValue = RecoverD2Cln_RowCompressedFormat_unmanaged(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, dp3_JacobianValue); 00401 00402 if(AF_available) reset(); 00403 00404 AF_available = true; 00405 i_AF_rowCount = g->GetRowVertexCount(); 00406 dp2_AF_Value = *dp3_JacobianValue; 00407 00408 return returnValue; 00409 } 00410 00411 int JacobianRecovery1D::RecoverD2Cln_SparseSolversFormat_usermem(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00412 if(g==NULL) { 00413 cerr<<"g==NULL"<<endl; 00414 return _FALSE; 00415 } 00416 00417 int rowCount = g->GetRowVertexCount(); 00418 vector<int> vi_RightVertexColors; 00419 g->GetRightVertexColors(vi_RightVertexColors); 00420 unsigned int numOfNonZeros = 0; 00421 00422 numOfNonZeros = g->GetEdgeCount(); 00423 00424 //Making the array indices to start at 0 instead of 1 00425 for(unsigned int i=0; i <= (unsigned int)rowCount; i++) { 00426 (*ip2_RowIndex)[i]--; 00427 } 00428 for(unsigned int i=0; i < numOfNonZeros; i++) { 00429 (*ip2_ColumnIndex)[i]--; 00430 } 00431 00432 //Recover value of the Jacobian 00433 //cout<<"Recover value of the Jacobian"<<endl; 00434 unsigned int numOfNonZerosInEachRow = 0; 00435 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00436 numOfNonZerosInEachRow = uip2_JacobianSparsityPattern[i][0]; 00437 for(unsigned int j=1; j <= numOfNonZerosInEachRow; j++) { 00438 (*dp2_JacobianValue)[(*ip2_RowIndex)[i]+j-1] = dp2_CompressedMatrix[i][vi_RightVertexColors[uip2_JacobianSparsityPattern[i][j]]]; 00439 } 00440 } 00441 00442 //Making the array indices to start at 1 instead of 0 to conform with theIntel MKL sparse storage scheme for the direct sparse solvers 00443 for(unsigned int i=0; i <= (unsigned int)rowCount; i++) { 00444 (*ip2_RowIndex)[i]++; 00445 } 00446 for(unsigned int i=0; i < numOfNonZeros; i++) { 00447 (*ip2_ColumnIndex)[i]++; 00448 } 00449 00450 return rowCount; 00451 } 00452 00453 int JacobianRecovery1D::RecoverD2Cln_SparseSolversFormat_unmanaged(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00454 if(g==NULL) { 00455 cerr<<"g==NULL"<<endl; 00456 return _FALSE; 00457 } 00458 00459 int rowCount = g->GetRowVertexCount(); 00460 unsigned int numOfNonZeros = 0; 00461 00462 // Allocate memory and populate ip2_RowIndex and ip2_ColumnIndex 00463 g->GetRowVertices(ip2_RowIndex); 00464 numOfNonZeros = g->GetColumnIndices(ip2_ColumnIndex); 00465 00466 //Making the array indices to start at 1 instead of 0 to conform with theIntel MKL sparse storage scheme for the direct sparse solvers 00467 for(unsigned int i=0; i <= (unsigned int)rowCount; i++) { 00468 (*ip2_RowIndex)[i]++; 00469 } 00470 for(unsigned int i=0; i < numOfNonZeros; i++) { 00471 (*ip2_ColumnIndex)[i]++; 00472 } 00473 00474 //cout<<"allocate memory for *dp2_JacobianValue rowCount="<<rowCount<<endl; 00475 //printf("i=%d\tnumOfNonZeros=%d \n", i, numOfNonZeros); 00476 (*dp2_JacobianValue) = (double*) malloc(numOfNonZeros * sizeof(double)); //allocate memory for *dp2_JacobianValue. 00477 for(unsigned int i=0; i < numOfNonZeros; i++) (*dp2_JacobianValue)[i] = 0.; //initialize value of other entries 00478 00479 return RecoverD2Cln_SparseSolversFormat_usermem(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00480 } 00481 00482 int JacobianRecovery1D::RecoverD2Cln_SparseSolversFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00483 int returnValue = RecoverD2Cln_SparseSolversFormat_unmanaged( g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00484 00485 if(SSF_available) reset(); 00486 00487 SSF_available = true; 00488 i_SSF_rowCount = g->GetRowVertexCount(); 00489 ip_SSF_RowIndex = *ip2_RowIndex; 00490 ip_SSF_ColumnIndex = *ip2_ColumnIndex; 00491 dp_SSF_Value = *dp2_JacobianValue; 00492 00493 return returnValue; 00494 } 00495 00496 int JacobianRecovery1D::RecoverD2Cln_CoordinateFormat_usermem(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00497 if(g==NULL) { 00498 cerr<<"g==NULL"<<endl; 00499 return _FALSE; 00500 } 00501 00502 int rowCount = g->GetRowVertexCount(); 00503 vector<int> vi_RightVertexColors; 00504 g->GetRightVertexColors(vi_RightVertexColors); 00505 unsigned int numOfNonZeros = 0; 00506 vector<int>* LeftVerticesPtr = g->GetLeftVerticesPtr(); 00507 00508 //Recover value of the Jacobian 00509 //cout<<"Recover value of the Jacobian"<<endl; 00510 #pragma omp parallel for default(none) schedule(static) shared(rowCount,LeftVerticesPtr,dp2_JacobianValue, ip2_RowIndex, ip2_ColumnIndex, uip2_JacobianSparsityPattern, dp2_CompressedMatrix, vi_RightVertexColors) private(numOfNonZeros) 00511 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00512 numOfNonZeros = uip2_JacobianSparsityPattern[i][0]; 00513 for(unsigned int j=1; j <= numOfNonZeros; j++) { 00514 (*dp2_JacobianValue)[(*LeftVerticesPtr)[i]+j-1] = dp2_CompressedMatrix[i][vi_RightVertexColors[uip2_JacobianSparsityPattern[i][j]]]; 00515 (*ip2_RowIndex)[(*LeftVerticesPtr)[i]+j-1] = i; 00516 (*ip2_ColumnIndex)[(*LeftVerticesPtr)[i]+j-1] = uip2_JacobianSparsityPattern[i][j]; 00517 } 00518 } 00519 00520 return (*LeftVerticesPtr)[rowCount]; 00521 } 00522 00523 int JacobianRecovery1D::RecoverD2Cln_CoordinateFormat_usermem_serial(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00524 if(g==NULL) { 00525 cerr<<"g==NULL"<<endl; 00526 return _FALSE; 00527 } 00528 00529 int rowCount = g->GetRowVertexCount(); 00530 vector<int> vi_RightVertexColors; 00531 g->GetRightVertexColors(vi_RightVertexColors); 00532 unsigned int numOfNonZeros = 0; 00533 00534 //Recover value of the Jacobian 00535 //cout<<"Recover value of the Jacobian"<<endl; 00536 unsigned int numOfNonZeros_count = 0; 00537 for(unsigned int i=0; i < (unsigned int)rowCount; i++) { 00538 numOfNonZeros = uip2_JacobianSparsityPattern[i][0]; 00539 for(unsigned int j=1; j <= numOfNonZeros; j++) { 00540 (*dp2_JacobianValue)[numOfNonZeros_count] = dp2_CompressedMatrix[i][vi_RightVertexColors[uip2_JacobianSparsityPattern[i][j]]]; 00541 (*ip2_RowIndex)[numOfNonZeros_count] = i; 00542 (*ip2_ColumnIndex)[numOfNonZeros_count] = uip2_JacobianSparsityPattern[i][j]; 00543 numOfNonZeros_count++; 00544 } 00545 } 00546 00547 return numOfNonZeros_count; 00548 } 00549 00550 int JacobianRecovery1D::RecoverD2Cln_CoordinateFormat_unmanaged_OMP(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00551 if(g==NULL) { 00552 cerr<<"g==NULL"<<endl; 00553 return _FALSE; 00554 } 00555 00556 unsigned int numOfNonZeros = g->GetEdgeCount(); 00557 00558 // !!! test the effectiveness of this sections. Will I really get any improvement? 00559 #pragma omp sections 00560 { 00561 #pragma omp section 00562 { 00563 (*ip2_RowIndex) = (unsigned int*) malloc(numOfNonZeros * sizeof(unsigned int)); 00564 } 00565 #pragma omp section 00566 { 00567 (*ip2_ColumnIndex) = (unsigned int*) malloc(numOfNonZeros * sizeof(unsigned int)); 00568 } 00569 #pragma omp section 00570 { 00571 (*dp2_JacobianValue) = (double*) malloc(numOfNonZeros * sizeof(double)); //allocate memory for *dp2_JacobianValue. 00572 } 00573 } 00574 00575 return RecoverD2Cln_CoordinateFormat_usermem(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00576 } 00577 00578 int JacobianRecovery1D::RecoverD2Cln_CoordinateFormat_unmanaged(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00579 if(g==NULL) { 00580 cerr<<"g==NULL"<<endl; 00581 return _FALSE; 00582 } 00583 00584 unsigned int numOfNonZeros = g->GetEdgeCount(); 00585 00586 (*ip2_RowIndex) = (unsigned int*) malloc(numOfNonZeros * sizeof(unsigned int)); 00587 (*ip2_ColumnIndex) = (unsigned int*) malloc(numOfNonZeros * sizeof(unsigned int)); 00588 (*dp2_JacobianValue) = (double*) malloc(numOfNonZeros * sizeof(double)); //allocate memory for *dp2_JacobianValue. 00589 00590 return RecoverD2Cln_CoordinateFormat_usermem_serial(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00591 } 00592 00593 int JacobianRecovery1D::RecoverD2Cln_CoordinateFormat_OMP(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00594 int returnValue = RecoverD2Cln_CoordinateFormat_unmanaged_OMP(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00595 00596 if(CF_available) reset(); 00597 00598 CF_available = true; 00599 i_CF_rowCount = g->GetRowVertexCount(); 00600 ip_CF_RowIndex = *ip2_RowIndex; 00601 ip_CF_ColumnIndex = *ip2_ColumnIndex; 00602 dp_CF_Value = *dp2_JacobianValue; 00603 00604 return returnValue; 00605 } 00606 00607 int JacobianRecovery1D::RecoverD2Cln_CoordinateFormat(BipartiteGraphPartialColoringInterface* g, double** dp2_CompressedMatrix, unsigned int ** uip2_JacobianSparsityPattern, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue) { 00608 int returnValue = RecoverD2Cln_CoordinateFormat_unmanaged(g, dp2_CompressedMatrix, uip2_JacobianSparsityPattern, ip2_RowIndex, ip2_ColumnIndex, dp2_JacobianValue); 00609 00610 if(CF_available) reset(); 00611 00612 CF_available = true; 00613 i_CF_rowCount = g->GetRowVertexCount(); 00614 ip_CF_RowIndex = *ip2_RowIndex; 00615 ip_CF_ColumnIndex = *ip2_ColumnIndex; 00616 dp_CF_Value = *dp2_JacobianValue; 00617 00618 return returnValue; 00619 } 00620 00621 int JacobianRecovery1D::CompareMatrix_CoordinateFormat_vs_CoordinateFormat(int i_rowCount, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue, unsigned int** ip2_RowIndex2, unsigned int** ip2_ColumnIndex2, double** dp2_JacobianValue2) { 00622 bool fail_flag=false; 00623 for(int i=0;i<i_rowCount;i++) { 00624 if((*ip2_RowIndex)[i]!=(*ip2_RowIndex2)[i]) { 00625 cout<<"i="<<i<<" (*ip2_RowIndex)[i] ("<< (*ip2_RowIndex)[i] <<")!=(*ip2_RowIndex2)[i] ("<< (*ip2_RowIndex2)[i] <<")"<<endl; 00626 fail_flag=true; 00627 break; 00628 } 00629 00630 if((*ip2_ColumnIndex)[i]!=(*ip2_ColumnIndex2)[i]) { 00631 cout<<"i="<<i<<" (*ip2_ColumnIndex)[i] ("<< (*ip2_ColumnIndex)[i] <<")!=(*ip2_ColumnIndex2)[i] ("<< (*ip2_ColumnIndex2)[i] <<")"<<endl; 00632 fail_flag=true; 00633 break; 00634 } 00635 00636 00637 if(!(*dp2_JacobianValue)[i]==(*dp2_JacobianValue2)[i] ) { 00638 cout<<"i="<<i<<" (*dp2_JacobianValue)[i] ("<< (*dp2_JacobianValue)[i] <<")!=(*dp2_JacobianValue2)[i] ("<< (*dp2_JacobianValue2)[i] <<")"<<endl; 00639 fail_flag=true; 00640 break; 00641 } 00642 00643 } 00644 00645 return (fail_flag)?0:1; 00646 } 00647 00648 int JacobianRecovery1D::CompareMatrix_CoordinateFormat_vs_RowCompressedFormat(int i_rowCount, unsigned int** ip2_RowIndex, unsigned int** ip2_ColumnIndex, double** dp2_JacobianValue, int rowCount2, unsigned int *** uip3_SparsityPattern, double*** dp3_Value) { 00649 bool fail_flag=false; 00650 for(int i=0;i<i_rowCount;i++) { 00651 if((*ip2_RowIndex)[i] >= rowCount2) { 00652 fail_flag = true; 00653 break; 00654 } 00655 00656 int j =0; 00657 for(;j<= (*uip3_SparsityPattern)[ (*ip2_RowIndex)[i] ][0];j++) { 00658 if((*uip3_SparsityPattern)[ (*ip2_RowIndex)[i] ][j] == (*ip2_ColumnIndex)[i]) break; 00659 } 00660 if(j>(*uip3_SparsityPattern)[ (*ip2_RowIndex)[i] ][0]) { 00661 fail_flag = true; 00662 break; 00663 } 00664 //cout<<"found j = "<<j<<endl; 00665 00666 if( !(*dp2_JacobianValue)[i]==(*dp3_Value)[(*ip2_RowIndex)[i]][j]) { 00667 cout<<"i="<<i<<" (*dp2_JacobianValue)[i] ("<< (*dp2_JacobianValue)[i] <<")!=(*dp3_Value)["<< (*ip2_RowIndex)[i] <<"]["<< (*ip2_ColumnIndex)[i] <<"] ("<<(*dp3_Value)[(*ip2_RowIndex)[i]][j]<<")"<<endl; 00668 fail_flag=true; 00669 break; 00670 } 00671 00672 } 00673 00674 return (fail_flag)?0:1; 00675 } 00676 }