#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"
#include "Epetra_CrsMatrix.h"
#include "Epetra_Time.h"
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
#else
#endif
bool verbose = (Comm.
MyPID() == 0);
int NumGlobalElements = 5;
double *Values = new double[2];
Values[0] = -1.0; Values[1] = -1.0;
int *Indices = new int[2];
double two = 2.0;
int NumEntries;
for( int i=0 ; i<NumMyElements; ++i ) {
if (MyGlobalElements[i]==0) {
Indices[0] = 1;
NumEntries = 1;
} else if (MyGlobalElements[i] == NumGlobalElements-1) {
Indices[0] = NumGlobalElements-2;
NumEntries = 1;
} else {
Indices[0] = MyGlobalElements[i]-1;
Indices[1] = MyGlobalElements[i]+1;
NumEntries = 2;
}
A.InsertGlobalValues(MyGlobalElements[i], NumEntries, Values, Indices);
A.InsertGlobalValues(MyGlobalElements[i], 1, &two, MyGlobalElements+i);
}
A.FillComplete();
z.PutScalar( 1.0 );
A.SetFlopCounter(counter);
A.Multiply(false, z, q);
double elapsed_time = timer.ElapsedTime();
double total_flops =counter.
Flops();
if (verbose)
cout << "Total ops: " << total_flops << endl;
double MFLOPs = total_flops/elapsed_time/1000000.0;
if (verbose)
cout << "Total MFLOPs for mat-vec = " << MFLOPs << endl<< endl;
double dotProduct;
z.SetFlopCounter(counter);
timer.ResetStartTime();
z.Dot(q, &dotProduct);
total_flops =counter.
Flops();
if (verbose)
cout << "Total ops: " << total_flops << endl;
elapsed_time = timer.ElapsedTime();
if (elapsed_time != 0.0)
MFLOPs = (total_flops / elapsed_time) / 1000000.0;
else
MFLOPs = 0;
if (verbose)
{
cout << "Total MFLOPs for vec-vec = " << MFLOPs << endl<< endl;
cout << "q dot z = " << dotProduct << endl;
}
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return( 0 );
}
#else
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
puts("Please configure Didasko with:\n"
"--enable-epetra");
return 0;
}
#endif