Gonzalo Tornaria on Wed, 4 Jun 2003 13:13:51 -0500 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
GEN serialisation |
I am writing some distributed PARI program that run in a network and comunicate using PVM. I need a way to serialise GENs so as to be able to transfer them back and forth. Does someone has sample code for this? -------------- As a first idea (to check my prototype implementation), I thought of using GENtostr and readseq. Question: is it guaranteed that readseq(GENtostr(x),0) == x provided GEN x is well formed? ------------- Back to "the right way" (TM), it shouldn't be that difficult to do it recursively. The idea would be to send the codewords (1 or 2?), and then recursively send the (GEN) components. I think the "lontyp" array is for this, but I'm not familiar with it. My understanding is the following: say we have a GEN x, and let lt=lontyp[typ(x)], len=lg(x). * if lt=0, the type is not recursive: * if lt>0, the type is recursive, with lt codewords, and the rest is more GENs ------------------------- assuming I have primitives send_long(long *data, int count); recv_long(long *data, int count); which send and receive "count" longs, I'd define send_GEN(GEN *data, int count) { for(int i=0; i<count; i++) { GEN x=data[i]; long lt=lontyp[typ(x)]; long len=lg(x); if(lt) { send_long(x, lt); send_GEN(x+lt, len-lt); } else { send_long(x, len); } } } to send, and recv_GEN(GEN *data, int count) { for(int i=0; i<count; i++) { long codeword; /* a "pseudo-GEN" */ GEN x=data[i]; long lt, len; recv_long(&codeword, 1); /* get the type and length */ lt=lontyp[typ(&codeword)]; len=lg(&codeword); x=cgetg(len,typ(&codeword)); x[0]=codeword; /* is this necesary ??? */ if(lt) { recv_long(x+1, lt-1); /* already recv 1 long */ recv_GEN(x+lt, len-lt); } else { recv_long(x+1, len-1); /* already recv 1 long */ } } } to receive (assumes GEN *data is already allocated). Am I missing something??? -------------------------------- Is it guaranteed that the first codeword has only length and type information??? I.e., after doing x=cgetg(lg(&codeword), typ(&codeword)), is it guaranteed that x[0]==codeword (assuming that codeword is the first codeword of a well formed GEN) Thanks, Gonzalo -- GM/CS/S d? a-- C++(+++) UL+++(++++) P++>+++ L+++>++++ E--- W-(+) N+(++) w--- O M-(--) V-(--) PGP(--) b++(+++) G++ e>++++ ... A mathematician is a machine for converting coffee into theorems.