Created
February 16, 2011 22:15
-
-
Save zonca/830379 to your computer and use it in GitHub Desktop.
test trilinos FEVBr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <list> | |
#include <string> | |
#include <math.h> | |
#include "Epetra_ConfigDefs.h" | |
#ifdef HAVE_MPI | |
#include "mpi.h" | |
#include "Epetra_MpiComm.h" | |
#else | |
#include "Epetra_SerialComm.h" | |
#endif | |
#include "Epetra_Map.h" | |
#include "Epetra_BlockMap.h" | |
#include "Epetra_FEVbrMatrix.h" | |
#include <EpetraExt_MatrixMatrix.h> | |
using namespace std; | |
int main(int argc, char *argv[]) | |
{ | |
#ifdef HAVE_MPI | |
MPI_Init(&argc, &argv); | |
Epetra_MpiComm Comm(MPI_COMM_WORLD); | |
#else | |
Epetra_SerialComm Comm; | |
#endif | |
int NSIDE = 1; | |
int NPIX ; | |
int NSTOKES = 3; | |
int NumElements; | |
NumElements = 11; | |
NPIX = 12. * NSIDE * NSIDE +1; //total pixel size, each pixel is an element which contains 3 floats which are IQU | |
Epetra_BlockMap PixMap(NPIX,NSTOKES,0,Comm); | |
int * PixMyGlobalElements = PixMap.MyGlobalElements(); | |
cout << PixMap << endl; | |
Epetra_FEVbrMatrix invM(Copy, PixMap, 1); | |
int BlockIndices[1]; | |
BlockIndices[0] = 2; | |
Epetra_SerialDenseMatrix *Prow; | |
int RowDim, NumBlockEntries; | |
int err; | |
Epetra_SerialDenseMatrix Mpp(NSTOKES, NSTOKES); | |
Mpp[0][0] = 1.; | |
cout << Mpp << endl; | |
int debugPID = 1; | |
int NumHits = 2*Comm.MyPID() + 5; | |
for( int i=0 ; i<NumHits; ++i ) { //loop on local pointing | |
invM.BeginSumIntoGlobalValues(BlockIndices[0], 1, BlockIndices); | |
err = invM.SubmitBlockEntry(Mpp.A(), Mpp.LDA(), NSTOKES, NSTOKES); //FIXME check order | |
if (err != 0) { | |
cout << "PID:" << Comm.MyPID() << "Error in inserting values in M, error code:" << err << endl; | |
} | |
err = invM.EndSubmitEntries(); | |
if (err != 0) { | |
cout << "PID:" << Comm.MyPID() << " LocalRow[i]:" << i << " Error in ending submit entries in M, error code:" << err << endl; | |
} | |
} | |
invM.GlobalAssemble(); | |
cout << invM << endl; | |
#ifdef HAVE_MPI | |
MPI_Finalize(); | |
#endif | |
return(0); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <list> | |
#include <string> | |
#include <math.h> | |
#include "Epetra_ConfigDefs.h" | |
#ifdef HAVE_MPI | |
#include "mpi.h" | |
#include "Epetra_MpiComm.h" | |
#else | |
#include "Epetra_SerialComm.h" | |
#endif | |
#include "Epetra_Map.h" | |
#include "Epetra_BlockMap.h" | |
#include "Epetra_FEVbrMatrix.h" | |
//#include "AztecOO.h" | |
#include <EpetraExt_MatrixMatrix.h> | |
using namespace std; | |
int main(int argc, char *argv[]) | |
{ | |
#ifdef HAVE_MPI | |
MPI_Init(&argc, &argv); | |
Epetra_MpiComm Comm(MPI_COMM_WORLD); | |
#else | |
Epetra_SerialComm Comm; | |
#endif | |
int NSIDE = 1; | |
int NPIX ; | |
int NSTOKES = 3; | |
int NumElements; | |
NumElements = 11; | |
NPIX = 12. * NSIDE * NSIDE +1; //total pixel size, each pixel is an element which contains 3 floats which are IQU | |
Epetra_BlockMap PixMap(NPIX,NSTOKES,0,Comm); | |
int * PixMyGlobalElements = PixMap.MyGlobalElements(); | |
cout << PixMap << endl; | |
Epetra_FEVbrMatrix invM(Copy, PixMap, 1); | |
int BlockIndices[1]; | |
BlockIndices[0] = 2; | |
Epetra_SerialDenseMatrix *Prow; | |
int RowDim, NumBlockEntries; | |
int err; | |
Epetra_SerialDenseMatrix Mpp(NSTOKES, NSTOKES); | |
Mpp[0][0] = 1.; | |
cout << Mpp << endl; | |
Epetra_SerialDenseMatrix * Zero; | |
for( int i=0 ; i<PixMap.NumMyElements(); ++i ) { //loop on local pixel | |
BlockIndices[0] = PixMyGlobalElements[i]; | |
Zero = new Epetra_SerialDenseMatrix(NSTOKES, NSTOKES); | |
invM.BeginInsertGlobalValues(BlockIndices[0], 1, BlockIndices); | |
err = invM.SubmitBlockEntry(Zero->A(), Zero->LDA(), NSTOKES, NSTOKES); | |
if (err != 0) { | |
cout << "PID:" << Comm.MyPID() << "Error in inserting init zero values in M, error code:" << err << endl; | |
} | |
err = invM.EndSubmitEntries(); | |
} | |
int debugPID = 1; | |
BlockIndices[0] = 2; | |
cout << invM << endl; | |
int NumHits = 2*Comm.MyPID() + 5; | |
for( int i=0 ; i<NumHits; ++i ) { //loop on local pointing | |
invM.BeginSumIntoGlobalValues(BlockIndices[0], 1, BlockIndices); | |
err = invM.SubmitBlockEntry(Mpp.A(), Mpp.LDA(), NSTOKES, NSTOKES); //FIXME check order | |
if (err != 0) { | |
cout << "PID:" << Comm.MyPID() << "Error in inserting values in M, error code:" << err << endl; | |
} | |
err = invM.EndSubmitEntries(); | |
if (err != 0) { | |
cout << "PID:" << Comm.MyPID() << " LocalRow[i]:" << i << " Error in ending submit entries in M, error code:" << err << endl; | |
} | |
} | |
invM.GlobalAssemble(); | |
cout << invM << endl; | |
#ifdef HAVE_MPI | |
MPI_Finalize(); | |
#endif | |
return(0); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks to Alan Williams:
The problem is that when you start the loop, the matrix doesn't contain any entries, and so it has an error when you try to sum-into a non-existent entry. If you use BeginInsertGlobalValues on the first iteration of your loop and then use BeginSumIntoGlobalValues on subsequent loop iterations, it should work as you expect.