#include "Didasko_ConfigDefs.h"
#if defined(HAVE_DIDASKO_EPETRA)
#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_Vector.h"
bool Vector2MATLAB( const Epetra_Vector & v,
const Epetra_Map & Map)
{
int MyPID = Map.Comm().MyPID();
int NumProc = Map.Comm().NumProc();
int MyLength = v.MyLength();
int GlobalLength = v.GlobalLength();
if( MyPID == 0 ) cout << "v = zeros(" << GlobalLength << ")\n";
int * MyGlobalElements = Map.MyGlobalElements( );
int Row;
for( int Proc=0 ; Proc<NumProc ; ++Proc ) {
if( MyPID == Proc ) {
cout << "% On proc " << Proc << ": ";
cout << MyLength << " rows of ";
cout << GlobalLength << " elements\n";
for( Row=0 ; Row<MyLength ; ++Row ) {
cout << "b(" << MyGlobalElements[Row]
<< ") = " << v[Row] << ";\n";
}
if( MyPID == NumProc-1 ) {
cout << "% End of vector\n";
}
}
Map.Comm().Barrier();
}
return true;
}
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 NumGlobalElements = 5;
Epetra_Map Map(NumGlobalElements,0,Comm);
Epetra_Vector A(Map);
A.Random();
Vector2MATLAB( A, Map );
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return( EXIT_SUCCESS );
}
#else
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
puts("Please configure Didasko with:\n"
"--enable-epetra");
return 0;
}
#endif