diff --git a/flint-extras/src/nmod_poly_mat_extra/profile/p-mul.c b/flint-extras/src/nmod_poly_mat_extra/profile/p-mul.c index 913204c0..a366f13a 100644 --- a/flint-extras/src/nmod_poly_mat_extra/profile/p-mul.c +++ b/flint-extras/src/nmod_poly_mat_extra/profile/p-mul.c @@ -16,7 +16,8 @@ typedef struct slong rdim; /* row outer dimension */ slong idim; /* inner dimension */ slong cdim; /* column outer dimension */ - slong deg; /* degree */ + slong degl; /* degree of left operand */ + slong degr; /* degree of right operand */ slong modn; /* modulus */ } time_args; @@ -27,7 +28,8 @@ void time_##fun(time_args targs, flint_rand_t state) \ const slong rdim = targs.rdim; \ const slong idim = targs.idim; \ const slong cdim = targs.cdim; \ - const slong deg = targs.deg; \ + const slong degl = targs.degl; \ + const slong degr = targs.degr; \ const slong n = targs.modn; \ \ nmod_t mod; \ @@ -35,10 +37,10 @@ void time_##fun(time_args targs, flint_rand_t state) \ \ nmod_poly_mat_t A; \ nmod_poly_mat_init(A, rdim, idim, n); \ - nmod_poly_mat_rand(A, state, deg); \ + nmod_poly_mat_rand(A, state, degl); \ nmod_poly_mat_t B; \ nmod_poly_mat_init(B, idim, cdim, n); \ - nmod_poly_mat_rand(B, state, deg); \ + nmod_poly_mat_rand(B, state, degr); \ nmod_poly_mat_t C; \ nmod_poly_mat_init(C, rdim, cdim, n); \ \ @@ -48,7 +50,7 @@ void time_##fun(time_args targs, flint_rand_t state) \ nmod_poly_mat_##fun(C, A, B); \ TIMEIT_STOP_VALUES(tcpu, twall); \ \ - printf("%.2e", twall); \ + flint_printf("%.2e", twall); \ \ nmod_poly_mat_clear(A); \ nmod_poly_mat_clear(B); \ @@ -57,6 +59,7 @@ void time_##fun(time_args targs, flint_rand_t state) \ TIME_MUL(mul) TIME_MUL(mul_geometric) +TIME_MUL(mul_waksman) /*-------------------------*/ /* main */ @@ -69,191 +72,147 @@ int main(int argc, char ** argv) flint_rand_set_seed(state, time(NULL), time(NULL)+129384125L); // modulus bitsize - const slong nbits = 7; - const ulong bits[] = {12, 24, 30, 40, 50, 60, 63}; + /* const slong nbits = 7; */ + /* const ulong bits[] = {12, 24, 30, 40, 50, 60, 63}; */ // matrix dimensions (all square for the moment) - const slong ndims = 10; - const ulong dims[] = {2, 4, 6, 8, 11, 15, 20, 30, 50, 100}; + /* const slong ndims = 10; */ + /* const ulong dims[] = {2, 4, 6, 8, 11, 15, 20, 30, 50, 100}; */ // matrix degrees const slong ndegs = 12; const ulong degs[] = {5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240}; // bench functions - const slong nfuns = 2; + const slong nfuns = 3; typedef void (*timefun) (time_args, flint_rand_t); const timefun funs[] = { time_mul, // 0 - time_mul_geometric, // 1 + time_mul_waksman, // 1 + time_mul_geometric, // 2 }; - // TODO - //typedef void (*samplefun) (void*, ulong); - //const samplefun sfuns[] = { - // sample_mul, // 0 - // sample_mul_geometric, // 1 - //}; + /* typedef void (*samplefun) (void*, ulong); */ + /* const samplefun sfuns[] = { */ + /* sample_mul, // 0 */ + /* sample_mul_waksman, // 1 */ + /* sample_mul_geometric, // 2 */ + /* }; */ const char * description[] = { "#0 --> mul ", - "#1 --> mul_geometric ", + "#1 --> mul_waksman ", + "#2 --> mul_geometric ", }; if (argc == 1) // show usage { - printf("Usage: `%s [nbits] [dim] [deg] [fun]`\n", argv[0]); - printf(" Each argument is optional; no argument shows this help.\n"); - printf(" - nbits: number of bits (in (1..64]) for the modulus, chosen as nextprime(2**(nbits-1))\n"); - printf(" (nbits == -1 launches full suite)\n"); - printf(" - dim: matrices are dim x dim\n"); - printf(" - deg: matrices are random of degree < deg\n"); - printf(" - fun: id number of the timed function (see below),\n"); - printf("\nAvailable functions:\n"); + flint_printf("Usage: `%s [nbits] [fun] [dim1] [dim2] [dim3] [degl] [degr]`\n", argv[0]); + flint_printf(" No argument shows this help.\n"); + flint_printf(" 6 arguments [nbits] [fun] [dim1] [dim2] [dim3] runs for several degrees.\n"); + /* flint_printf(" 4 arguments [nbits] [fun] [dim] [deg] is the square dim x dim case.\n"); */ + /* flint_printf(" 3 arguments [nbits] [fun] [dim] does several degrees in the square dim x dim case.\n"); */ + flint_printf(" - nbits: number of bits (in (1..64]) for the modulus, chosen as nextprime(2**(nbits-1))\n"); + flint_printf(" - fun: id number of the timed function (see below),\n"); + flint_printf(" (fun == -1 launches all available functions)\n"); + flint_printf(" - dim1, dim2, dim3: matrices are dim1 x dim2 and dim2 x dim3\n"); + flint_printf(" - deg: matrices are random of degree < deg\n"); + flint_printf("\nAvailable functions:\n"); for (slong j = 0; j < nfuns; j++) - printf(" %s\n", description[j]); + flint_printf(" %s\n", description[j]); return 0; } - printf("#warmup...\n"); + flint_printf("#warmup...\n"); for (slong i = 0; i < 3; i++) { - time_args targs = {4, 4, 4, 1000, UWORD(1) << 20}; + time_args targs = {4, 4, 4, 1000, 1000, UWORD(1) << 20}; time_mul(targs, state); - printf(" "); + flint_printf(" "); } - printf("\n\n"); + flint_printf("\n\n"); - if (argc == 2 && atoi(argv[1]) == -1) // launching full suite + if (argc == 8) // nbits + fun + dim1 + dim2 + dim3 + degl + degr { - printf(" dim"); - for (slong i = 0; i < ndims; i++) - printf("%17ld", dims[i]); - printf("\n"); - printf("bits fun deg\n"); - for (slong j = 0; j < nbits; j++) + const slong b = atoi(argv[1]); + slong ifun = atoi(argv[2]); + const slong dim1 = atoi(argv[3]); + const slong dim2 = atoi(argv[4]); + const slong dim3 = atoi(argv[5]); + const slong degl = atoi(argv[6]); + const slong degr = atoi(argv[7]); + flint_printf("bits fun dim1 dim2 dim3 degl degr\n"); + + ulong n; + n = n_nextprime(UWORD(1) << (b-1), 0); + + if (ifun == -1) { - const slong b = bits[j]; - ulong n; - n = n_nextprime(UWORD(1) << (b-1), 0); - for (slong ifun = 0; ifun < nfuns; ifun++) + for (ifun = 0; ifun < nfuns; ifun++) { - for (slong d = 0; d < ndegs; d++) - { - printf("%-5ld#%-3ld%-8ld", b, ifun, degs[d]); - for (slong i = 0; i < ndims; i++) - { - time_args targs = {dims[i], dims[i], dims[i], degs[d], n}; - -#if MEASURE_SAMPLE - const samplefun sfun = sfuns[ifun]; - double min, max; - prof_repeat(&min, &max, sfun, (void*) &targs); - printf("%.2e", min/1000000); -#else - const timefun tfun = funs[ifun]; - tfun(targs, state); -#endif - printf(" "); - } - } - printf("\n"); + const timefun tfun = funs[ifun]; + flint_printf("%-5ld#%-3ld%-5ld%-5ld%-5ld%-8ld%-8ld", b, ifun, dim1, dim2, dim3, degl, degr); + time_args targs = {dim1, dim2, dim3, degl, degr, n}; + tfun(targs, state); + flint_printf("\n"); } } + else + { + const timefun tfun = funs[ifun]; + flint_printf("%-5ld#%-3ld%-5ld%-5ld%-5ld%-8ld%-8ld", b, ifun, dim1, dim2, dim3, degl, degr); + time_args targs = {dim1, dim2, dim3, degl, degr, n}; + tfun(targs, state); + } + + flint_printf(" "); + flint_printf("\n"); } - else if (argc == 2) // nbits is given + else if (argc == 6) // nbits + fun + dim1 + dim2 + dim3 { - printf(" dim"); - for (slong i = 0; i < ndims; i++) - printf("%17ld", dims[i]); - printf("\n"); - printf("bits fun deg\n"); const slong b = atoi(argv[1]); + slong ifun = atoi(argv[2]); + const slong dim1 = atoi(argv[3]); + const slong dim2 = atoi(argv[4]); + const slong dim3 = atoi(argv[5]); + flint_printf("bits fun dim1 dim2 dim3 degl degr\n"); + ulong n; n = n_nextprime(UWORD(1) << (b-1), 0); - for (slong ifun = 0; ifun < nfuns; ifun++) + + if (ifun == -1) { - const timefun tfun = funs[ifun]; - for (slong d = 0; d < ndegs; d++) + for (ifun = 0; ifun < nfuns; ifun++) { - printf("%-5ld#%-3ld%-8ld", b, ifun, degs[d]); - for (slong i = 0; i < ndims; i++) + const timefun tfun = funs[ifun]; + for (slong ideg = 0; ideg < ndegs; ideg++) { - time_args targs = {dims[i], dims[i], dims[i], degs[d], n}; + const slong deg = degs[ideg]; + flint_printf("%-5ld#%-3ld%-5ld%-5ld%-5ld%-8ld%-8ld", b, ifun, dim1, dim2, dim3, deg, deg); + time_args targs = {dim1, dim2, dim3, deg, deg, n}; tfun(targs, state); - printf(" "); + flint_printf("\n"); } } - printf("\n"); } - } - else if (argc == 3) // nbits + dim given - { - const slong dim = atoi(argv[2]); - printf(" dim"); - printf("%17ld", dim); - printf("\n"); - printf("bits fun deg\n"); - const slong b = atoi(argv[1]); - ulong n; - n = n_nextprime(UWORD(1) << (b-1), 0); - for (slong ifun = 0; ifun < nfuns; ifun++) + else { const timefun tfun = funs[ifun]; - for (slong d = 0; d < ndegs; d++) + for (slong ideg = 0; ideg < ndegs; ideg++) { - printf("%-5ld#%-3ld%-8ld", b, ifun, degs[d]); - time_args targs = {dim, dim, dim, degs[d], n}; + const slong deg = degs[ideg]; + flint_printf("%-5ld#%-3ld%-5ld%-5ld%-5ld%-8ld%-8ld", b, ifun, dim1, dim2, dim3, deg, deg); + time_args targs = {dim1, dim2, dim3, deg, deg, n}; tfun(targs, state); - printf(" "); - printf("\n"); } } - } - else if (argc == 4) // nbits + dim + deg given - { - const slong dim = atoi(argv[2]); - const slong deg = atoi(argv[3]); - printf(" dim"); - printf("%17ld", dim); - printf("\n"); - printf("bits fun deg\n"); - const slong b = atoi(argv[1]); - ulong n; - n = n_nextprime(UWORD(1) << (b-1), 0); - for (slong ifun = 0; ifun < nfuns; ifun++) - { - const timefun tfun = funs[ifun]; - printf("%-5ld#%-3ld%-8ld", b, ifun, deg); - time_args targs = {dim, dim, dim, deg, n}; - tfun(targs, state); - printf(" "); - printf("\n"); - } - } - else if (argc == 5) // nbits + dim + deg + fun given - { - const slong b = atoi(argv[1]); - const slong dim = atoi(argv[2]); - const slong deg = atoi(argv[3]); - const slong ifun = atoi(argv[4]); - const timefun tfun = funs[ifun]; - printf(" dim"); - printf("%17ld", dim); - printf("\n"); - printf("bits fun deg\n"); - ulong n; - n = n_nextprime(UWORD(1) << (b-1), 0); - printf("%-5ld#%-3ld%-8ld", b, ifun, deg); - time_args targs = {dim, dim, dim, deg, n}; - tfun(targs, state); - - printf(" "); - printf("\n"); + flint_printf(" "); + flint_printf("\n"); } + flint_rand_clear(state); return 0; }