Hello,

I had posted this before about calls to libraries in a loop:

www.pgroup.com/userforum/viewtopic.php?p=19304

I was advised to try inlining or to try defining routine information. I went with the latter as it generally seemed to work, but then I ran into a problem. The two methods I had defined are mentioned as an undefined reference with nvlink.

I did the following to define the routines:

```
#pragma acc routine seq
extern __GMP_DECLSPEC void mpz_init_set_si (mpz_ptr, signed long int);
#pragma acc routine seq
extern void mpz_clear (mpz_ptr);
```

and then when I run:

```
pgc++ -fast -ta=tesla,cc30 -Minfo=all -Minline=levels:3 -lgmpxx -lgmp main.cpp
```

I get the following output:

```
main:
17, Generating copy(vals[:])
19, Generating copy(t)
21, Loop is parallelizable
Accelerator kernel generated
Generating Tesla code
21, #pragma acc loop gang, vector(128) /* blockIdx.x threadIdx.x */
25, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(int) inlined, size=2 (inline) file main.cpp (1423)
1423, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_si(long) inlined, size=7, file main.cpp (1389)
1391, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_ui(unsigned long) inlined, size=4 (inline) file main.cpp (1382)
1394, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_ui(unsigned long) inlined, size=4 (inline) file main.cpp (1382)
1395, __gmpz_neg inlined, size=4 (inline) file main.cpp (1801)
26, Loop is parallelizable
30, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr() inlined, size=2 (inline) file main.cpp (1444)
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_si(long):
1391, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_ui(unsigned long) inlined, size=4 (inline) file main.cpp (1382)
1394, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_ui(unsigned long) inlined, size=4 (inline) file main.cpp (1382)
1395, __gmpz_neg inlined, size=4 (inline) file main.cpp (1801)
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(int):
1423, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_si(long) inlined, size=7 (inline) file main.cpp (1389)
1391, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_ui(unsigned long) inlined, size=4, file main.cpp (1382)
1394, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_ui(unsigned long) inlined, size=4, file main.cpp (1382)
1395, __gmpz_neg inlined, size=4, file main.cpp (1801)
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(int) [subobject]:
0, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(int) inlined, size=2 (inline) file main.cpp (1423)
1423, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_si(long) inlined, size=7, file main.cpp (1389)
1391, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_ui(unsigned long) inlined, size=4 (inline) file main.cpp (1382)
1394, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_ui(unsigned long) inlined, size=4 (inline) file main.cpp (1382)
1395, __gmpz_neg inlined, size=4 (inline) file main.cpp (1801)
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr() [subobject]:
0, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr() inlined, size=2 (inline) file main.cpp (1444)
nvlink error : Undefined reference to '__gmpz_init_set_si' in '/tmp/pgc++MZZfYrbrP8To.o'
nvlink error : Undefined reference to '__gmpz_clear' in '/tmp/pgc++MZZfYrbrP8To.o'
pgacclnk: child process exit status 2: /opt/pgi/linux86-64/15.7/bin/pgnvd
```

As you can see, there is some sort of nvlink error. I can’t quite understand how to go about resolving it. Any ideas?

It should be noted that __gmpz_init_set_si is defined as mpz_init_set_si in the gmp header file. Use of either one as the routine definition allows the compiler to get up to this point. If I don’t define a routine for either, the compiler says the loop is not parallelizable due to undefined routine information.

Thanks,