View Single Post
Old 2012-10-28, 18:31   #9
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

4,001 Posts
Default

This is my latest very basic testing setup from start to finish.

pariTest.gp:
Code:
pTest(a,b)=
{
  for(e=a,b,
    print("e is ",e)
  )
}
terminal session:
Code:
[user@comp pari]$ gp2c-run -g pariTest.gp
                  GP/PARI CALCULATOR Version 2.3.5 (released)
          amd64 running linux (x86-64/GMP-4.3.2 kernel) 64-bit version
      compiled: Feb  8 2011, gcc-4.6.0 20110205 (Red Hat 4.6.0-0.6) (GCC) 
    (readline v6.2 enabled [was v6.1 in Configure], extended help available)

                     Copyright (C) 2000-2006 The PARI Group

PARI/GP is free software, covered by the GNU General Public License, and 
comes WITHOUT ANY WARRANTY WHATSOEVER.

Type ? for help, \q to quit.
Type ?12 for how to get moral (and possibly technical) support.

parisize = 8000000, primelimit = 500000
? pTest(11,17)
e is 11
e is 12
e is 13
e is 14
e is 15
e is 16
e is 17
?
generated pariTest.gp.c
Code:
/*-*- compile-command: "/usr/bin/gcc -c -o pariTest.gp.o -O3 -Wall -fno-strict-aliasing -fomit-frame-pointer -fPIC -I/usr/include pariTest.gp.c && /usr/bin/gcc -o pariTest.gp.so -shared -O3 -Wall -fno-strict-aliasing -fomit-frame-pointer -fPIC -Wl,-shared pariTest.gp.o -lc -ldl -lm -L/usr/lib64 -lgmp -L/usr/lib64 -lpari"; -*-*/
#include <pari/pari.h>
/*
GP;install("init_pariTest","v","init_pariTest","./pariTest.gp.so");
GP;install("pTest","vD0,G,D0,G,","pTest","./pariTest.gp.so");
*/
void init_pariTest(void);
void pTest(GEN a, GEN b);
/*End of prototype*/

void
init_pariTest(void)      /* void */
{
  pari_sp ltop = avma;
  avma = ltop;
  return;
}

void
pTest(GEN a, GEN b)      /* void */
{
  pari_sp ltop = avma;
  {
    pari_sp btop = avma, st_lim = stack_lim(btop, 1);
    GEN e = gen_0;
    for (e = gcopy(a); gcmp(e, b) <= 0; e = gaddgs(e, 1))
    {
      pariprintf("e is %Z\n", e);
      if (low_stack(st_lim, stack_lim(btop, 1)))
        e = gerepilecopy(btop, e);
    }
  }
  avma = ltop;
  return;
}
c program:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "pari.h"

void init_pariTest(void);
void pTest(GEN a, GEN b);


int main()
{
    GEN c, d;

    c=utoipos(11);
    d=utoipos(17);

    pari_init(1e9,1e8);
    init_pariTest();

    pTest(c,d);

    pari_close();

    printf("\nFinished!\n");
    return 0;
}

void
init_pariTest(void)      /* void */
{
  pari_sp ltop = avma;
  avma = ltop;
  return;
}

void
pTest(GEN a, GEN b)      /* void */
{
  pari_sp ltop = avma;
  {
    pari_sp btop = avma, st_lim = stack_lim(btop, 1);
    GEN e = gen_0;
    for (e = gcopy(a); gcmp(e, b) <= 0; e = gaddgs(e, 1))
    {
      pariprintf("e is %Z\n", e);
      if (low_stack(st_lim, stack_lim(btop, 1)))
        e = gerepilecopy(btop, e);
    }
  }
  avma = ltop;
  return;
}
c program session output:
Code:
Process returned -1 (0xFFFFFFFF)   execution time : 0.004 s
Press ENTER to continue.
debugger output:
Code:
Building to ensure sources are up-to-date
Build succeeded
Selecting target: 
Release
Adding source dir: /home/user/Programming/pariTest/
Adding source dir: /home/user/Programming/pariTest/
Adding file: bin/Release/pariTest
Starting debugger: 
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
(no debugging symbols found)...done.
Debugger name and version: GNU gdb (GDB) Fedora (7.3.50.20110722-16.fc16)
Program received signal SIGSEGV, Segmentation fault.
In pariputc () (/usr/lib64/libpari-gmp.so.2)
My program console gives me the following message:
Code:
warning: GDB: Failed to set controlling terminal: Operation not permitted
Call stack:
Code:
#0 0x36e27f53fd    pariputc() (/usr/lib64/libpari-gmp.so.2:??)
#1 0x36e27fe74a    pari_err() (/usr/lib64/libpari-gmp.so.2:??)
#2 (    0x0000000000400976 in ??() (??:??)
#3 (    0x000000000040099f in ??() (??:??)
#4 (    0x00000000004009db in ??() (??:??)
#5 (    0x0000000000400a15 in ??() (??:??)
#6 0x36e122169d    __libc_start_main() (/lib64/libc.so.6:??)
#7 (    0x0000000000400839 in ??() (??:??)
#8 (    0x00007fffffffe708 in ??() (??:??)
#9 (    0x000000000000001c in ??() (??:??)
#10 (    0x0000000000000001 in ??() (??:??)
#11 (    0x00007fffffffea03 in ??() (??:??)
#12 (    0x0000000000000000 in ??() (??:??)
Thanks for any help. I have the aforementioned documents and am looking into them. I haven't tried constructing this in the referenced Makefile manner, since I've never programmed with makefiles. I have started looking into them, though...
EdH is offline   Reply With Quote