Annotation of OpenXM_contrib2/asir2000/lib/dmul, Revision 1.1
1.1 ! noro 1: /* $OpenXM$ */
! 2: #define MAX(a,b) ((a)>(b)?(a):(b))
! 3: #define MIN(a,b) ((a)>(b)?(b):(a))
! 4:
! 5: /* CAUTION: functions in this file are experimental. */
! 6:
! 7: /*
! 8: return: F1*F2
! 9: if option 'proc' is supplied as a list of server id's,
! 10: F1*F2 is calculated by distributed computation.
! 11: */
! 12:
! 13: def d_mul(F1,F2)
! 14: {
! 15: Procs = getopt(proc);
! 16: if ( type(Procs) == -1 )
! 17: Procs = [];
! 18: NP = length(Procs)+1;
! 19: V =var(F1);
! 20: D1 = deg(F1,V);
! 21: D2 = deg(F2,V);
! 22: Dmin = MIN(D1,D2);
! 23: Dfft = p_mag(D1+D2+1)+1;
! 24: Bound = maxblen(F1)+maxblen(F2)+p_mag(Dmin)+1;
! 25:
! 26: Marray = newvect(NP);
! 27: MIarray = newvect(NP);
! 28: for ( I = 0; I < NP; I++ ) {
! 29: Marray[I] = 1;
! 30: MIarray[I] = [];
! 31: }
! 32:
! 33: for ( M = 1, I = 0, J = 0; p_mag(M) <= Bound; J = (J+1)%NP ) {
! 34: T = get_next_fft_prime(I,Dfft);
! 35: if ( !T )
! 36: error("fft_mul_d : fft_prime exhausted.");
! 37: Marray[J] *= T[1];
! 38: MIarray[J] = cons(T[0],MIarray[J]);
! 39: M *= T[1];
! 40: I = T[0]+1;
! 41: }
! 42: /* Now,
! 43: Marray[J] = FFTprime[Marray[J][0]]*...*FFTprime[Marray[J][...]]
! 44: M = Marray[0]*...*Marray[NP-1]
! 45: */
! 46: C = newvect(NP);
! 47: T0 = time();
! 48: for ( J = 0; J < NP-1; J++ )
! 49: ox_cmo_rpc(Procs[J],"call_umul",F1,F2,MIarray[J],Marray[J],M);
! 50: T1 = time();
! 51: R = call_umul(F1,F2,MIarray[NP-1],Marray[NP-1],M);
! 52: T2 = time();
! 53: for ( J = 0; J < NP-1; J++ )
! 54: R += ox_pop_cmo(Procs[J]);
! 55: T3 = time();
! 56: print(["send",T1[3]-T0[3],"self",T2[3]-T1[3],"recv",T3[3]-T2[3]]);
! 57: return R%M;
! 58: }
! 59:
! 60: /*
! 61: return: F1^2
! 62: if option 'proc' is supplied as a list of server id's,
! 63: F1^2 is calculated by distributed computation.
! 64: */
! 65:
! 66: def d_square(F1)
! 67: {
! 68: Procs = getopt(proc);
! 69: if ( type(Procs) == -1 )
! 70: Procs = [];
! 71: NP = length(Procs)+1;
! 72: V =var(F1);
! 73: D1 = deg(F1,V);
! 74: Dfft = p_mag(2*D1+1)+1;
! 75: Bound = 2*maxblen(F1)+p_mag(D1)+1;
! 76:
! 77: Marray = newvect(NP);
! 78: MIarray = newvect(NP);
! 79: for ( I = 0; I < NP; I++ ) {
! 80: Marray[I] = 1;
! 81: MIarray[I] = [];
! 82: }
! 83:
! 84: for ( M = 1, I = 0, J = 0; p_mag(M) <= Bound; J = (J+1)%NP ) {
! 85: T = get_next_fft_prime(I,Dfft);
! 86: if ( !T )
! 87: error("fft_mul_d : fft_prime exhausted.");
! 88: Marray[J] *= T[1];
! 89: MIarray[J] = cons(T[0],MIarray[J]);
! 90: M *= T[1];
! 91: I = T[0]+1;
! 92: }
! 93: /* Now,
! 94: Marray[J] = FFTprime[Marray[J][0]]*...*FFTprime[Marray[J][...]]
! 95: M = Marray[0]*...*Marray[NP-1]
! 96: */
! 97: C = newvect(NP);
! 98: T0 = time();
! 99: for ( J = 0; J < NP-1; J++ )
! 100: ox_cmo_rpc(Procs[J],"call_usquare",F1,MIarray[J],Marray[J],M);
! 101: T1 = time();
! 102: R = call_usquare(F1,MIarray[NP-1],Marray[NP-1],M);
! 103: T2 = time();
! 104: for ( J = 0; J < NP-1; J++ )
! 105: R += ox_pop_cmo(Procs[J]);
! 106: T3 = time();
! 107: print(["send",T1[3]-T0[3],"self",T2[3]-T1[3],"recv",T3[3]-T2[3]]);
! 108: return R%M;
! 109: }
! 110:
! 111: /*
! 112: return: F1^2 mod V^(D+1)
! 113: if option 'proc' is supplied as a list of server id's,
! 114: F1*F2 mod V^(D+1) is calculated by distributed computation.
! 115: */
! 116:
! 117: def d_tmul(F1,F2,D)
! 118: {
! 119: Procs = getopt(proc);
! 120: if ( type(Procs) == -1 )
! 121: Procs = [];
! 122: NP = length(Procs)+1;
! 123: V =var(F1);
! 124: D1 = deg(F1,V);
! 125: D2 = deg(F2,V);
! 126: Dmin = MIN(D1,D2);
! 127: Dfft = p_mag(D1+D2+1)+1;
! 128: Bound = maxblen(F1)+maxblen(F2)+p_mag(Dmin)+1;
! 129:
! 130: Marray = newvect(NP);
! 131: MIarray = newvect(NP);
! 132: for ( I = 0; I < NP; I++ ) {
! 133: Marray[I] = 1;
! 134: MIarray[I] = [];
! 135: }
! 136:
! 137: for ( M = 1, I = 0, J = 0; p_mag(M) <= Bound; J = (J+1)%NP ) {
! 138: T = get_next_fft_prime(I,Dfft);
! 139: if ( !T )
! 140: error("fft_mul_d : fft_prime exhausted.");
! 141: Marray[J] *= T[1];
! 142: MIarray[J] = cons(T[0],MIarray[J]);
! 143: M *= T[1];
! 144: I = T[0]+1;
! 145: }
! 146: /* Now,
! 147: Marray[J] = FFTprime[Marray[J][0]]*...*FFTprime[Marray[J][...]]
! 148: M = Marray[0]*...*Marray[NP-1]
! 149: */
! 150: C = newvect(NP);
! 151: T0 = time();
! 152: for ( J = 0; J < NP-1; J++ )
! 153: ox_cmo_rpc(Procs[J],"call_utmul",F1,F2,D,MIarray[J],Marray[J],M);
! 154: T1 = time();
! 155: R = call_utmul(F1,F2,D,MIarray[NP-1],Marray[NP-1],M);
! 156: T2 = time();
! 157: for ( J = 0; J < NP-1; J++ )
! 158: R += ox_pop_cmo(Procs[J]);
! 159: T3 = time();
! 160: print(["send",T1[3]-T0[3],"self",T2[3]-T1[3],"recv",T3[3]-T2[3]]);
! 161: return R%M;
! 162: }
! 163:
! 164: def call_umul(F1,F2,Ind,M1,M)
! 165: {
! 166: C = umul_specialmod(F1,F2,Ind);
! 167: Mhat = idiv(M,M1);
! 168: MhatInv = inv(Mhat,M1);
! 169: return (MhatInv*Mhat)*C;
! 170: }
! 171:
! 172: def call_usquare(F1,Ind,M1,M)
! 173: {
! 174: C = usquare_specialmod(F1,Ind);
! 175: Mhat = idiv(M,M1);
! 176: MhatInv = inv(Mhat,M1);
! 177: return (MhatInv*Mhat)*C;
! 178: }
! 179:
! 180: def call_utmul(F1,F2,D,Ind,M1,M)
! 181: {
! 182: C = utmul_specialmod(F1,F2,D,Ind);
! 183: Mhat = idiv(M,M1);
! 184: MhatInv = inv(Mhat,M1);
! 185: return (MhatInv*Mhat)*C;
! 186: }
! 187: end$
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>