Skip to content

Instantly share code, notes, and snippets.

@hube12
Created May 8, 2020 01:05
Show Gist options
  • Save hube12/51c8bb82d7c6f4cdcf65ab096b5189f8 to your computer and use it in GitHub Desktop.
Save hube12/51c8bb82d7c6f4cdcf65ab096b5189f8 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <NTL/ZZ.h>
#include <NTL/vec_double.h>
#include <NTL/vec_ZZ.h>
#include <NTL/mat_ZZ.h>
#include <NTL/mat_RR.h>
#include <NTL/LLL.h>
#include <iostream>
#include <fstream>
#include <mm_malloc.h>
using namespace std;
int dim;
double **mu;
double *B;
void computeNewVector(long* dst_vec, int* src_vec ,long** base){
int i,l;
for (i = 0; i < dim; i++){
for (l = 0; l < dim; l++){
dst_vec[l] += -src_vec[i] * base[i][l];
}
}
}
void MatIntFromMatZZ(long** A, NTL::mat_ZZ B) {
int row,col, rows = (int)B.NumRows(), cols= (int)B.NumCols();
for (row = 0; row < rows; ++row) {
for (col = 0; col < cols; ++col) {
A[row][col] = to_long(B[row][col]);
}
}
}
void check_equals(int* vec, int* ntl, int rows){
int mult = 1, equal = 1, i;
if(vec[0] == -ntl[0]){
mult = -1;
}
for(i = 0;i < rows;i++){
if(vec[i] != mult*ntl[i]){equal=0;}
}
if(equal==1){
printf("Vectors match\n");
}else{
printf("WARNING vectors do not match\n");
}
}
int main(int argc, const char * argv[]) {
/* int aux, Events[]={PAPI_L3_TCW,PAPI_L3_TCM};
long long values[NUM_EVENTS];
clock_t inicio,fim;
float totT=0.0;
float real_time, proc_time, mflops;
long long flpops;
float ireal_time, iproc_time, imflops;
long long iflpops;
*/
NTL::mat_ZZ BB;
std::ifstream input_file(argv[1]);
//Try to read Base file
if (input_file.is_open()) {
input_file >> BB;
input_file.close();
}
else{
printf("File was not read\n");
exit(-1);
}
//To call LLL or BKZ of NTL
NTL::G_BKZ_FP(BB, 0.99, 11 ); //BKZ janela 20
//Basis Matrix - Memory Allocation
int rows = (int)BB.NumRows(), cols= (int)BB.NumCols();
long** BB_ = (long**)_mm_malloc((rows+1) *sizeof(long*),64);
for(int row = 0; row < rows+1; row++)
BB_[row] = (long*)_mm_malloc(cols*sizeof(long),64);
//Convert ZZ data to double
MatIntFromMatZZ(BB_, BB);
for (int j = 0; j < BB.NumCols(); ++j) {
for (int i = 0; i < BB.NumRows(); ++i) {
printf("%ld ",BB_[i][j]);
}
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment