[Trilinos-Users] epetra example program

narendiran kumar narendirankumar at gmail.com
Tue Apr 12 04:06:51 MDT 2011


Dear Sir/Madam,

I am trying to run some of the example program in epetra (new directory).
But, In some case, i got error with " undefined reference to '...' "

Is it problem with linking library.  Can anyone please help me.

root at narendiran:/home2/program/sample/example/epetra_ex1# ls
cxx_main.cpp  Makefile  power_method.cpp
root at narendiran:/home2/program/sample/example/epetra_ex1# make

Found Trilinos!  Here are the details:
   Trilinos_VERSION = 10.6.4
   Trilinos_PACKAGE_LIST = Triutils Epetra
   Trilinos_LIBRARIES = -ltriutils -lepetra
   Trilinos_INCLUDE_DIRS = -I/home2/trilinos-10.6.4-Source/build/include
   Trilinos_LIBRARY_DIRS = -L/home2/trilinos-10.6.4-Source/build/lib
   Trilinos_TPL_LIST = LAPACK BLAS
   Trilinos_TPL_INCLUDE_DIRS =
   Trilinos_TPL_LIBRARIES = /usr/lib/liblapack.so /usr/lib/libblas.so
   Trilinos_TPL_LIBRARY_DIRS =
   Trilinos_BUILD_SHARED_LIBS = ON
End of Trilinos details

/usr/bin/g++ -c -g -O0  -I/home2/trilinos-10.6.4-Source/build/include
-DMYAPP_EPETRA cxx_main.cpp
/usr/bin/ar cr libmyappLib.a cxx_main.o
/usr/bin/g++ -g -O0  libmyappLib.a -o MyApp.exe
-I/home2/trilinos-10.6.4-Source/build/include  -DMYAPP_EPETRA
-L/home2/trilinos-10.6.4-Source/build/lib  -ltriutils -lepetra
/usr/lib/liblapack.so /usr/lib/libblas.so
libmyappLib.a(cxx_main.o): In function `main':
/home2/program/sample/example/epetra_ex1/cxx_main.cpp:108: undefined
reference to `power_method(Epetra_CrsMatrix const&)'
collect2: ld returned 1 exit status
make: *** [MyApp.exe] Error 1
root at narendiran:/home2/program/sample/example/epetra_ex1#


Regards,
K. Narendiran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://software.sandia.gov/pipermail/trilinos-users/attachments/20110412/df491a6b/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 2570 bytes
Desc: not available
Url : https://software.sandia.gov/pipermail/trilinos-users/attachments/20110412/df491a6b/attachment.obj 
-------------- next part --------------
/*
//@HEADER
// ************************************************************************
// 
//               Epetra: Linear Algebra Services Package 
//                 Copyright 2001 Sandia Corporation
// 
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Michael A. Heroux (maherou at sandia.gov) 
// 
// ************************************************************************
//@HEADER
*/

#include <stdio.h>
#include <stdlib.h>
#include "Epetra_config.h"
#ifdef HAVE_MPI
#include "mpi.h"
#include "Epetra_MpiComm.h"
#else
#include "Epetra_SerialComm.h"
#endif
#include "Epetra_Map.h"
#include "Epetra_IntSerialDenseVector.h"
#include "Epetra_SerialDenseVector.h"
#include "Epetra_Vector.h"
#include "Epetra_CrsMatrix.h"
#include "Epetra_Version.h"
                                            
// prototype
double power_method(const Epetra_CrsMatrix& A);
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
  MPI_Init(&argc,&argv);
  Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
  Epetra_SerialComm Comm;
#endif

  if (Comm.MyPID()==0)
    cout << Epetra_Version() << endl << endl;

  cout << Comm << endl; // Print out process information
  // Get the number of global equations from the command line
  if (argc!=2) { 
    cout << "Usage: " << argv[0] << " number_of_equations" << endl;
    exit(1);
   }
  int NumGlobalElements = atoi(argv[1]);
  // Construct a Map that puts approximately the same number of 
  // equations on each processor.
  Epetra_Map Map(NumGlobalElements, 0, Comm);
  // Get update list and number of local equations from newly created Map.
  int NumMyElements = Map.NumMyElements();
  // Create an Epetra_CrsMatrix
  Epetra_CrsMatrix A(Copy, Map, 1);
 // Add  rows one-at-a-time
  Epetra_SerialDenseVector DiagVal(1); 
  DiagVal[0] = 2.0; // We set all diagonal values to 2
  Epetra_IntSerialDenseVector ColIndices(1);
  for (int i=0; i<NumMyElements; i++) {
    int RowIndex = Map.GID(i);
    ColIndices[0] = RowIndex;
    // Put in the diagonal entry
    A.InsertGlobalValues(RowIndex, DiagVal.Length(), 
			 DiagVal.Values(), ColIndices.Values());  
  }
  if (Map.MyGID(0)) { // Change the first global diagonal value to 4.0
    DiagVal[0] = 4.0;
    int RowIndex = 0;
    ColIndices[0] = RowIndex;
  A.ReplaceGlobalValues(RowIndex, DiagVal.Length(), 
			DiagVal.Values(), ColIndices.Values());
  }
  // Finish up
 A.FillComplete();
  // Iterate
  double lambda = power_method(A);
  if (Comm.MyPID()==0) 
    cout << endl << "Estimate of Dominant Eigenvalue = " << lambda << endl;		
#ifdef UG_EX1_MPI
  MPI_Finalize() ;
#endif
return 0;
}
-------------- next part --------------
//@HEADER
// ************************************************************************
// 
//               Epetra: Linear Algebra Services Package 
//                 Copyright 2001 Sandia Corporation
// 
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Michael A. Heroux (maherou at sandia.gov) 
// 
// ************************************************************************
//@HEADER


#include <stdio.h>
#include <stdlib.h>
#include "Epetra_Comm.h"
#include "Epetra_Map.h"
#include "Epetra_Vector.h"
#include "Epetra_CrsMatrix.h"
// Simple Power method algorithm
double power_method(const Epetra_CrsMatrix& A) {  
  // variable needed for iteration
  double lambda = 0.0;
  int niters = A.RowMap().NumGlobalElements()*10;
  double tolerance = 1.0e-10;
  // Create vectors
  Epetra_Vector q(A.RowMap());
  Epetra_Vector z(A.RowMap());
  Epetra_Vector resid(A.RowMap());
  // Fill z with random Numbers
  z.Random();
  // variable needed for iteration
  double normz;
  double residual = 0;
  int iter = 0;
  while (iter==0 || (iter < niters && residual > tolerance)) {
    z.Norm2(&normz); // Compute 2-norm of z
    q.Scale(1.0/normz, z);
    A.Multiply(false, q, z); // Compute z = A*q
    q.Dot(z, &lambda); // Approximate maximum eigenvalue
    if (iter%10==0 || iter+1==niters) {
      // Compute A*q - lambda*q every 10 iterations
      resid.Update(1.0, z, -lambda, q, 0.0);
      resid.Norm2(&residual);
      if (q.Map().Comm().MyPID()==0)
	cout << "Iter = " << iter << "  Lambda = " << lambda 
	     << "  Two-norm of A*q - lambda*q = " 
	     << residual << endl;
    } 
    iter++;
  }
  return(lambda);
}


More information about the Trilinos-Users mailing list