int test_pluq_solve_left(rci_t m, rci_t n, int offsetA, int offsetB) { mzd_t* Abase = mzd_init(2048, 2048); mzd_t* Bbase = mzd_init(2048, 2048); mzd_randomize(Abase); mzd_randomize(Bbase); mzd_t* A = mzd_init_window(Abase, 0, offsetA, m, m + offsetA); mzd_t* B = mzd_init_window(Bbase, 0, offsetB, m, n + offsetB); // copy B mzd_t* Bcopy = mzd_init(B->nrows, B->ncols); for (rci_t i = 0; i < B->nrows; ++i) for (rci_t j = 0; j < B->ncols; ++j) mzd_write_bit(Bcopy,i,j, mzd_read_bit (B,i,j)); for (rci_t i = 0; i < m; ++i) { mzd_write_bit(A,i,i, 1); } mzd_t *Acopy = mzd_copy(NULL, A); rci_t r = mzd_echelonize(Acopy,1); printf("solve_left m: %4d, n: %4d, r: %4d da: %4d db: %4d ", m, n, r, offsetA, offsetB); mzd_free(Acopy); Acopy = mzd_copy(NULL, A); int consistency = mzd_solve_left(A, B, 0, 1); //copy B mzd_t *X = mzd_init(B->nrows,B->ncols); for (rci_t i = 0; i < B->nrows; ++i) for (rci_t j = 0; j < B->ncols; ++j) mzd_write_bit(X,i,j, mzd_read_bit (B,i,j)); mzd_t *B1 = mzd_mul(NULL, Acopy, X, 0); mzd_t *Z = mzd_add(NULL, Bcopy, B1); int status = 0; if(consistency == 0) { status = 1 - mzd_is_zero(Z); if (status == 0) { printf("passed\n"); } else { printf("FAILED\n"); } } else { printf("skipped (no solution)\n"); } mzd_free(Bcopy); mzd_free(B1); mzd_free(Z); mzd_free_window(A); mzd_free_window(B); mzd_free(Acopy); mzd_free(Abase); mzd_free(Bbase); mzd_free(X); return status; }
int test_lqup_random(size_t m, size_t n) { printf("pluq: testing random m: %5zd, n: %5zd",m,n); size_t i,j; mzd_t* U = mzd_init(m, n); mzd_t* L = mzd_init(m, m); mzd_t* A = mzd_init(m, n); mzd_randomize(A); mzd_t* Acopy = mzd_copy (NULL,A); mzp_t* P = mzp_init(m); mzp_t* Q = mzp_init(n); int r; r=mzd_pluq(A, P, Q, 0); printf(", rank: %5d ",r); for (i=0; i<r; ++i){ for (j=0; j<i;++j) mzd_write_bit(L, i, j, mzd_read_bit(A,i,j)); for (j=i+1; j<n;++j) mzd_write_bit(U, i, j, mzd_read_bit(A,i,j)); } for (i=r; i<m; i++) for (j=0; j<r;++j) mzd_write_bit(L, i, j, mzd_read_bit(A,i,j)); for (i=0; i<r; ++i){ mzd_write_bit(L,i,i, 1); mzd_write_bit(U,i,i, 1); } mzd_apply_p_left(Acopy, P); mzd_apply_p_right_trans(Acopy, Q); mzd_addmul(Acopy, L, U, 0); int status = 0; for ( i=0; i<m; ++i) for ( j=0; j<n; ++j){ if (mzd_read_bit (Acopy,i,j)){ status = 1; break; } } if (status) { printf(" ... FAILED\n"); } else printf (" ... passed\n"); mzd_free(U); mzd_free(L); mzd_free(A); mzd_free(Acopy); mzp_free(P); mzp_free(Q); return status; }
int test_trsm_upper_right (int m, int n, int offset, const char* description){ printf("upper_right: %s m: %4d n: %4d offset: %4d ... ",description, m, n, offset); mzd_t* Ubase = mzd_init (2048,2048); mzd_t* Bbase = mzd_init (2048,2048); mzd_randomize (Ubase); mzd_randomize (Bbase); mzd_t* Bbasecopy = mzd_copy (NULL, Bbase); mzd_t* U = mzd_init_window (Ubase, 0, offset, n, offset + n); mzd_t* B = mzd_init_window (Bbase, 0, offset, m, offset + n); mzd_t* W = mzd_copy (NULL, B); size_t i,j; for (i=0; i<n; ++i){ for (j=0; j<i;++j) mzd_write_bit(U,i,j, 0); mzd_write_bit(U,i,i, 1); } mzd_trsm_upper_right (U, B, 2048); mzd_addmul(W, B, U, 2048); int status = 0; for ( i=0; i<m; ++i) for ( j=0; j<n; ++j){ if (mzd_read_bit (W,i,j)){ status = 1; } } // Verifiying that nothing has been changed around the submatrices mzd_addmul(W, B, U, 2048); mzd_copy (B, W); for ( i=0; i<2048; ++i) for ( j=0; j<2048/RADIX; ++j){ if (Bbase->rows[i][j] != Bbasecopy->rows[i][j]){ status = 1; } } mzd_free_window (U); mzd_free_window (B); mzd_free (W); mzd_free(Ubase); mzd_free(Bbase); mzd_free(Bbasecopy); if (!status) printf("passed\n"); else printf("FAILED\n"); return status; }
int test_trsm_lower_left (int m, int n, int offsetL, int offsetB){ mzd_t* Lbase = mzd_init (2048,2048); mzd_t* Bbase = mzd_init (2048,2048); mzd_randomize (Lbase); mzd_randomize (Bbase); mzd_t* Bbasecopy = mzd_copy (NULL, Bbase); mzd_t* L = mzd_init_window (Lbase, 0, offsetL, m, offsetL + m); mzd_t* B = mzd_init_window (Bbase, 0, offsetB, m, offsetB + n); mzd_t* W = mzd_copy (NULL, B); size_t i,j; for (i=0; i<m; ++i){ for (j=i+1; j<m;++j) mzd_write_bit(L,i,j, 0); mzd_write_bit(L,i,i, 1); } mzd_trsm_lower_left(L, B, 2048); mzd_addmul(W, L, B, 2048); int status = 0; for ( i=0; i<m; ++i) for ( j=0; j<n; ++j){ if (mzd_read_bit (W,i,j)){ status = 1; } } // Verifiying that nothing has been changed around the submatrices mzd_addmul(W, L, B, 2048); mzd_copy (B, W); for ( i=0; i<2048; ++i) for ( j=0; j<2048/RADIX; ++j){ if (Bbase->rows[i][j] != Bbasecopy->rows[i][j]){ status = 1; } } mzd_free_window (L); mzd_free_window (B); mzd_free_window (W); mzd_free(Lbase); mzd_free(Bbase); mzd_free(Bbasecopy); if (!status) printf(" ... passed\n"); else printf(" ... FAILED\n"); return status; }
mzd_t *mzd_kernel_left_pluq(mzd_t *A, int const cutoff) { mzp_t *P = mzp_init(A->nrows); mzp_t *Q = mzp_init(A->ncols); rci_t r = mzd_pluq(A, P, Q, cutoff); if (r == A->ncols) { mzp_free(P); mzp_free(Q); __M4RI_DD_MZD(A); return NULL; } mzd_t *U = mzd_init_window(A, 0, 0, r, r); mzd_t *B = mzd_init_window(A, 0, r, r, A->ncols); mzd_trsm_upper_left(U, B, cutoff); mzd_t *R = mzd_init(A->ncols, A->ncols - r); mzd_t *RU = mzd_init_window(R, 0, 0, r, R->ncols); mzd_copy(RU, B); for(rci_t i = 0; i < R->ncols; ++i) { mzd_write_bit(R, r + i, i, 1); } mzd_apply_p_left_trans(R, Q); mzp_free(P); mzp_free(Q); mzd_free_window(RU); mzd_free_window(U); mzd_free_window(B); __M4RI_DD_MZD(A); __M4RI_DD_MZD(R); return R; }
/* * File: m4ri_matrix_impl * Implementation of remaining matrix operations based on * M4RI library */ int copy_matrix_to_offset(gf2matrix *dest, const gf2matrix *src, int dest_offset_row, int dest_offset_col) { size_t i, j; if (!src) return -1; for (i = 0; i < src->nrows; ++i) { for (j = 0; j < src->ncols; ++j) { BIT bit = mzd_read_bit(src, i, j); mzd_write_bit(dest, dest_offset_row + i, dest_offset_col + j, bit); } } return 0; }
int run(void *_p, unsigned long long *data, int *data_len) { struct trsm_params *p = (struct trsm_params *)_p; *data_len = 2; mzd_t *B = mzd_init(p->m, p->n); mzd_t *L = mzd_init(p->n, p->n); mzd_randomize(B); mzd_randomize(L); for (rci_t i = 0; i < p->n; ++i){ for (rci_t j = i + 1; j < p->n; ++j) mzd_write_bit(L,i,j, 0); mzd_write_bit(L,i,i, 1); } data[0] = walltime(0); data[1] = cpucycles(); mzd_trsm_lower_right(L, B, 2048); data[0] = walltime(data[0]); data[1] = cpucycles() - data[1]; mzd_free(B); mzd_free(L); return 0; }
/* * Class: m4rjni_Mzd * Method: mzd_write_bit * Signature: (JIII)V */ JNIEXPORT void JNICALL Java_m4rjni_Mzd_mzd_1write_1bit(JNIEnv *env, jobject obj, jlong ptr, jint row, jint col, jint val) { mzd_t *M = (mzd_t*)ptr; if (M==NULL) return; rci_t rrow = row; rci_t rcol = col; rci_t rval = val; if (rrow<0 || rrow>=M->nrows) { printf("M4RJNI ERROR: invalid row index\n"); return; } if (rcol<0 || rcol>=M->ncols) { printf("M4RJNI ERROR: invalid column index\n"); return; } //printf("Java_m4rjni_Mzd_mzd_1write_1bit(%016lX, %d, %d, %d)\n",ptr,rrow,rcol,rval); mzd_write_bit(M, rrow, rcol, rval); }
void MatrixF2::set(uint r,uint c,uint64_t value) { inRowEchelonForm = false; mzd_write_bit(matrix,r,c,value); }
int run(void *_p, unsigned long long *data, int *data_len) { struct elim_params *p = (struct elim_params *)_p; #ifndef HAVE_LIBPAPI *data_len = 2; #else *data_len = MIN(papi_array_len + 1, *data_len); #endif int papi_res; mzd_t *A = mzd_init(p->m, p->n); if(p->r != 0) { mzd_t *L, *U; L = mzd_init(p->m, p->m); U = mzd_init(p->m, p->n); mzd_randomize(U); mzd_randomize(L); for (rci_t i = 0; i < p->m; ++i) { for (rci_t j = i + 1; j < p->m; j+=m4ri_radix) { int const length = MIN(m4ri_radix, p->m - j); mzd_clear_bits(L, i, j, length); } mzd_write_bit(L,i,i, 1); for (rci_t j = 0; j < i && j < p->n; j+=m4ri_radix) { int const length = MIN(m4ri_radix, i - j); mzd_clear_bits(U, i, j, length); } if(i < p->r) { mzd_write_bit(U, i, i, 1); } else { for (rci_t j = i; j < p->n; j+=m4ri_radix) { int const length = MIN(m4ri_radix, p->n - i); mzd_clear_bits(U, i, j, length); } } } mzd_mul(A,L,U,0); mzd_free(L); mzd_free(U); } else { mzd_randomize(A); } mzp_t *P = mzp_init(A->nrows); mzp_t *Q = mzp_init(A->ncols); #ifndef HAVE_LIBPAPI data[0] = walltime(0); data[1] = cpucycles(); #else int array_len = *data_len - 1; unsigned long long t0 = PAPI_get_virt_usec(); papi_res = PAPI_start_counters((int*)papi_events, array_len); if (papi_res) m4ri_die(""); #endif if(strcmp(p->algorithm, "m4ri") == 0) p->r = mzd_echelonize_m4ri(A, 0, 0); else if(strcmp(p->algorithm, "ple") == 0) p->r = mzd_ple(A, P, Q, 0); else if(strcmp(p->algorithm, "mmpf") == 0) p->r = _mzd_ple_russian(A, P, Q, 0); else m4ri_die("unknown algorithm %s",p->algorithm); #ifndef HAVE_LIBPAPI data[1] = cpucycles() - data[1]; data[0] = walltime(data[0]); #else mzp_free(P); mzp_free(Q); PAPI_stop_counters((long long*)&data[1], array_len); t0 = PAPI_get_virt_usec() - t0; data[0] = t0; for (int nv = 0; nv <= array_len; ++nv) { data[nv] -= loop_calibration[nv]; } #endif mzd_free(A); return 0; }
int run_nothing(void *_p, unsigned long long *data, int *data_len) { struct elim_params *p = (struct elim_params *)_p; mzd_t *A = mzd_init(p->m, p->n); if(p->r != 0) { mzd_t *L, *U; L = mzd_init(p->m, p->m); U = mzd_init(p->m, p->n); mzd_randomize(U); mzd_randomize(L); for (rci_t i = 0; i < p->m; ++i) { for (rci_t j = i + 1; j < p->m; j+=m4ri_radix) { int const length = MIN(m4ri_radix, p->m - j); mzd_clear_bits(L, i, j, length); } mzd_write_bit(L,i,i, 1); for (rci_t j = 0; j < i && j <p->n; j+=m4ri_radix) { int const length = MIN(m4ri_radix, i - j); mzd_clear_bits(U, i, j, length); } if(i < p->r) { mzd_write_bit(U, i, i, 1); } else { for (rci_t j = i; j < p->n; j+=m4ri_radix) { int const length = MIN(m4ri_radix, p->n - j); mzd_clear_bits(U, i, j, length); } } } mzd_mul(A,L,U,0); mzd_free(L); mzd_free(U); } else { mzd_randomize(A); } #ifndef HAVE_LIBPAPI *data_len = 2; #else *data_len = MIN(papi_array_len + 1, *data_len); #endif int papi_res; #ifndef HAVE_LIBPAPI data[0] = walltime(0); data[1] = cpucycles(); #else int array_len = *data_len - 1; unsigned long long t0 = PAPI_get_virt_usec(); papi_res = PAPI_start_counters((int*)papi_events, array_len); if(papi_res) m4ri_die(""); #endif #ifndef HAVE_LIBPAPI data[1] = cpucycles() - data[1]; data[0] = walltime(data[0]); #else PAPI_stop_counters((long long*)&data[1], array_len); t0 = PAPI_get_virt_usec() - t0; data[0] = t0; for (int nv = 0; nv <= array_len; ++nv) { if (data[nv] < loop_calibration[nv]) loop_calibration[nv] = data[nv]; } #endif mzd_free(A); return (0); }
void set_bit_at(gf2matrix *m, int bit, int row, int col) { if (!m) return; mzd_write_bit(m, row, col, bit); }
int test_lqup_half_rank(size_t m, size_t n) { printf("pluq: testing half rank m: %5zd, n: %5zd",m,n); mzd_t* U = mzd_init(m, n); mzd_t* L = mzd_init(m, m); mzd_t* U2 = mzd_init(m, n); mzd_t* L2 = mzd_init(m, m); mzd_t* A = mzd_init(m, n); mzd_randomize (U); mzd_randomize (L); size_t i,j; for (i=0; i<m && i<n; ++i){ mzd_write_bit(U,i,i, 1); for (j=0; j<i;++j) mzd_write_bit(U,i,j, 0); if (i%2) for (j=i; j<n;++j) mzd_write_bit(U,i,j, 0); for (j=i+1; j<m;++j) mzd_write_bit(L,i,j, 0); mzd_write_bit(L,i,i, 1); } mzd_mul(A, L, U, 0); mzd_t* Acopy = mzd_copy (NULL,A); mzp_t* Pt = mzp_init(m); mzp_t* Q = mzp_init(n); int r = mzd_pluq(A, Pt, Q, 0); for (i=0; i<r; ++i){ for (j=0; j<i;++j) mzd_write_bit (L2, i, j, mzd_read_bit(A,i,j)); for (j=i+1; j<n;++j) mzd_write_bit (U2, i, j, mzd_read_bit(A,i,j)); } for (i=r; i<m; i++) for (j=0; j<r;++j) mzd_write_bit (L2, i, j, mzd_read_bit(A,i,j)); for (i=0; i<r; ++i){ mzd_write_bit(L2,i,i, 1); mzd_write_bit(U2,i,i, 1); } mzd_apply_p_left(Acopy, Pt); mzd_apply_p_right_trans(Acopy, Q); mzd_addmul(Acopy,L2,U2,0); int status = 0; for ( i=0; i<m; ++i) { for ( j=0; j<n; ++j){ if (mzd_read_bit(Acopy,i,j)){ status = 1; } } if(status) break; } if (status) printf(" ... FAILED\n"); else printf (" ... passed\n"); mzd_free(U); mzd_free(L); mzd_free(U2); mzd_free(L2); mzd_free(A); mzd_free(Acopy); mzp_free(Pt); mzp_free(Q); return status; }
int test_lqup_full_rank (size_t m, size_t n){ printf("pluq: testing full rank m: %5zu, n: %5zu",m,n); mzd_t* U = mzd_init (m,n); mzd_t* L = mzd_init (m,m); mzd_t* U2 = mzd_init (m,n); mzd_t* L2 = mzd_init (m,m); mzd_t* A = mzd_init (m,n); mzd_randomize (U); mzd_randomize (L); size_t i,j; for (i=0; i<m; ++i){ for (j=0; j<i && j<n;++j) mzd_write_bit(U,i,j, 0); for (j=i+1; j<m;++j) mzd_write_bit(L,i,j, 0); if(i<n) mzd_write_bit(U,i,i, 1); mzd_write_bit(L,i,i, 1); } mzd_mul(A, L, U, 2048); mzd_t* Acopy = mzd_copy (NULL,A); mzp_t* P = mzp_init(m); mzp_t* Q = mzp_init(n); mzd_pluq(A, P, Q, 2048); for (i=0; i<m; ++i){ for (j=0; j<i && j <n;++j) mzd_write_bit (L2, i, j, mzd_read_bit(A,i,j)); for (j=i+1; j<n;++j) mzd_write_bit (U2, i, j, mzd_read_bit(A,i,j)); } for (i=0; i<n && i<m; ++i){ mzd_write_bit(L2,i,i, 1); mzd_write_bit(U2,i,i, 1); } mzd_addmul(Acopy,L2,U2,0); int status = 0; for ( i=0; i<m; ++i) for ( j=0; j<n; ++j){ if (mzd_read_bit (Acopy,i,j)){ status = 1; } } if (status){ printf(" ... FAILED\n"); } else printf (" ... passed\n"); mzd_free(U); mzd_free(L); mzd_free(U2); mzd_free(L2); mzd_free(A); mzd_free(Acopy); mzp_free(P); mzp_free(Q); return status; }