#ifndef __SUBPROBLEM_H__ #define __SUBPROBLEM_H__ extern "C" { #include } #include #include #include NTL_CLIENT #define SUBPROBLEM_DESC_LEN (2 + (WORDS*3 + 3 + 1)*sizeof(unsigned int)) struct Subproblem { unsigned short problemid; ZZ base; ZZ target; ZZ modulus; ZZ order; unsigned int dpfreq; unsigned char desc[1 + SUBPROBLEM_DESC_LEN]; // Update the binary description of the subproblem. This is what // gets sent to the dpnodes and workers. void updatedesc(void) { desc[0] = 'P'; memmove(desc+1, &problemid, 2); BytesFromZZ(desc+3, base, WORDS*sizeof(unsigned int)); BytesFromZZ(desc+3+WORDS*sizeof(unsigned int), target, WORDS*sizeof(unsigned int)); BytesFromZZ(desc+3+2*WORDS*sizeof(unsigned int), modulus, WORDS*sizeof(unsigned int)); BytesFromZZ(desc+3+3*WORDS*sizeof(unsigned int), order, 3*sizeof(unsigned int)); memmove(desc+3+(3*WORDS+3)*sizeof(unsigned int), &dpfreq, sizeof(unsigned int)); } Subproblem(unsigned short id, const ZZ &b, const ZZ &t, const ZZ &m, const ZZ &o, unsigned int dpf) : problemid(id), base(b), target(t), modulus(m), order(o), dpfreq(dpf) { updatedesc(); } // Initilize the Subproblem from the binary description, *without* // the leading 'P' Subproblem(const unsigned char *descnoP) { desc[0] = 'P'; memmove(desc+1, descnoP, SUBPROBLEM_DESC_LEN); memmove(&problemid, desc+1, 2); ZZFromBytes(base, desc+3, WORDS*sizeof(unsigned int)); ZZFromBytes(target, desc+3+WORDS*sizeof(unsigned int), WORDS*sizeof(unsigned int)); ZZFromBytes(modulus, desc+3+2*WORDS*sizeof(unsigned int), WORDS*sizeof(unsigned int)); ZZFromBytes(order, desc+3+3*WORDS*sizeof(unsigned int), 3*sizeof(unsigned int)); memmove(&dpfreq, desc+3+(3*WORDS+3)*sizeof(unsigned int), sizeof(unsigned int)); } // Dump for debug purposes void dump(ostream &os) const { os << "Subproblem " << problemid << "\n"; os << "base = " << base << "\n"; os << "target = " << target << "\n"; os << "modulus = " << modulus << "\n"; os << "order = " << order << "\n"; os << "dpfreq = " << dpfreq << "\n"; } // Write the subproblem to the given bufferevent void bev_write(struct bufferevent *bev) { bufferevent_write(bev, desc, 1 + SUBPROBLEM_DESC_LEN); } }; #endif