Solving linear system of equations using AztecOO

After almost several days struggling with Trilinos eventually I built and Installed the library. Now I'm trying to run a simple test to get more into Trilinos but I'm getting some linker errors. Here is the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "AztecOO.h"
#include "AztecOO_Version.h"
#include "Epetra_SerialComm.h"
#include "Epetra_Map.h"
#include "Epetra_Vector.h"
#include "Epetra_CrsMatrix.h"


int main(int argc, char* argv[]) {
	Epetra_SerialComm Comm;

	int NumMyElements = 1000;

	if (Comm.MyPID() == 0)
		std::cout << AztecOO_Version() << std::endl;

	std::cout << Comm << std::endl;
	


	Epetra_Map Map(-1, NumMyElements, 0, Comm);
	int NumGlobalElements = Map.NumGlobalElements();
	Epetra_CrsMatrix A(Copy, Map, 3);

	double negOne = -1.0;
	double posTwo = 2.0;
	for (int i = 0; i < NumMyElements; i++) {
		int GlobalRow = A.GRID(i); int RowLess1 = GlobalRow - 1; int RowPlus1 = GlobalRow + 1;

		if (RowLess1 != -1) A.InsertGlobalValues(GlobalRow, 1, &negOne, &RowLess1);
		if (RowPlus1 != NumGlobalElements) A.InsertGlobalValues(GlobalRow, 1, &negOne, &RowPlus1);
		A.InsertGlobalValues(GlobalRow, 1, &posTwo, &GlobalRow);
	};

	A.FillComplete();
	Epetra_Vector x(Map);
	Epetra_Vector b(Map);
	b.Random();
	Epetra_LinearProblem problem(&A, &x, &b);
	AztecOO solver(problem);
	solver.SetAztecOption(AZ_precond, AZ_Jacobi);
	solver.Iterate(10, 1.0E-2);

	std::cout << "Solver performed " << solver.NumIters() << " iterations." << std::endl;
	std::cout << "Norm of true residual = " << solver.TrueResidual() << std::endl;

	for (int i = 0; i < 10; i++) {
		std::cout << x[i] << std::endl;
	}

	return 0;
}

There are lots of errors but all of them are the same.

Error	LNK2019	unresolved external symbol "public: virtual int __cdecl Epetra_CrsMatrix::InsertGlobalValues
(int,int,double *,int *)" (?InsertGlobalValues@Epetra_CrsMatrix@@UEAAHHHPEANPEAH@Z) referenced in function main


Thanks for your help in advance.
Last edited on
I know nothing about AztecOO.

...but this kind of error would indicate that you use classes from AztecOO in your code, probably by #include 'ing their header file(s), but you did not actually link the corresponding library to your program!

Note: Header files usually only contain type/function/class declarations, but the actual implementation is in the library file. Library files usually have a .a or .lib file extension (or .so for "shared" libraries).
Last edited on
The static libraries are included and that's why I don't understand these errors and post this question here.
Which platform?

If this is on the Windows platform, a special #define may be needed - in the code that calls functions from the library, before the #include of the header files - in order to get the static library working.

On Windows, library header files usually declare functions and classes with the __declspec(dllimport) attribute, since that is required to import symbols from a DLL; but it will not work with a static library at all!

That is why often you will see something like this in the header file (example from pthreads4w):
1
2
3
4
5
6
7
8
9
#if defined __PTW32_STATIC_LIB
# define __PTW32_DLLPORT
#elif defined  __PTW32_BUILD
# define  __PTW32_DLLPORT __declspec (dllexport)
#else
# define  __PTW32_DLLPORT __declspec (dllimport)
#endif

__PTW32_DLLPORT int pthread_create(/* ... */);


Here you'd have to #define __PTW32_STATIC_LIB in order to use the static library.

(AztecOO may have something similar)
Last edited on
Thanks for your answer. I managed this problem but I have another problem. This Trilinos is becoming like an never-ending maze. When compiling the Trilinos I get lots of errors which all of them are the same. here is the error.

Error   C2953   'Kokkos::Impl::FunctorAnalysis<PatternInterface,Policy,Functor>::DeduceTeamShmem<F,
std::enable_if<0<,void>::type>': class template has already been defined    kokkoskernels


The error refers to the last line of the following piece of code taken from KOKKOS,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
template <class F>
  struct DeduceTeamShmem<
      F, typename std::enable_if<0 < sizeof(&F::team_shmem_size)>::type> {
    enum : bool { value = true };

    static size_t team_shmem_size(F const* const f, int team_size) {
      return f->team_shmem_size(team_size);
    }
  };

  template <class F>
  struct DeduceTeamShmem<
      F, typename std::enable_if<0 < sizeof(&F::shmem_size)>::type> {
    enum : bool { value = true };

    static size_t team_shmem_size(F const* const f, int team_size) {
      return f->shmem_size(team_size);
    }
  };
See here:
https://stackoverflow.com/a/10157472

If this problem exists within library code that is not yours, it would have to fixed upstream....
Last edited on
Thanks for sharing the link. As I read this post there are two possible solution. #Pragma once and

1
2
3
4
5
6
#ifndef EMPLE_H
#define EMPLE_H

// your template class

#endif 


But this is an open source code. Where should I ad these fixes?
Yeah, #include guards are the usual approach to avoid including the same header file more than once, thus preventing errors resulting from multiple definitions of the same type, function, class or template.

If the problem is in a third-party library, then you should probably report it to the author.

Chances for a quick fix in third-party code can be increased by providing a patch along with your bug report 😃
Last edited on
Topic archived. No new replies allowed.