Skip to content

Commit

Permalink
rewrote do_skip_pivs()
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonidPryadko committed Aug 6, 2024
1 parent cebcd93 commit 1b3d7c3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
47 changes: 25 additions & 22 deletions src/dist_m4ri.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,43 @@
#include "util_io.h"
#include "dist_m4ri.h"




/** @brief prepare an ordered pivot-skip list of length `n-rank` */
mzp_t * do_skip_pivs(const size_t rank, const mzp_t * const pivs){
mzp_t * do_skip_pivs(const int rank, const mzp_t * const pivs){
const rci_t n=pivs->length;
rci_t j1=rank; /** position to insert the next result */
mzp_t * ans = mzp_copy(NULL,pivs);
qsort(ans->values, rank, sizeof(pivs->values[0]), cmp_rci_t);

for(rci_t j=0; j<n; j++){
if(!bsearch(&j, ans->values, rank, sizeof(ans->values[0]), cmp_rci_t)){
ans->values[j1++]=j;
}
int *arr=calloc(rank,sizeof(int));
if(!arr)
ERROR("memory allocation");
for(int i=0; i< rank; i++)
arr[i] = pivs->values[i];
qsort(arr, rank, sizeof(arr[0]), cmp_rci_t);
mzp_t *ans=mzp_init(n-rank);
rci_t j=0, j1=0; /** position to insert the next result */
for(rci_t i1=0; i1 < rank; i1++, j++){
const rci_t piv=arr[i1];
while(j<piv)
ans->values[j1++] = j++;
}
assert(j1==n);

int j=rank;
for(size_t i=0; j<n; j++)
ans->values[i++] = ans->values[j];
ans->length = n-rank;
while(j<n)
ans->values[j1++] = j++;
assert(j1==n-rank);

#ifndef NDEBUG
if(prm.debug&1024){/** in skip_pivs */
printf("orig pivs of len=%d, rank=%d: ",pivs->length, rank);
for(int i=0; i< rank; i++)
printf(" %d%s",pivs->values[i],i+1 == rank ?"\n":"");
printf("srtd pivs of len=%d: ", rank);
for(int i=0; i< rank; i++)
printf(" %d%s",arr[i],i+1 == rank ?"\n":"");
printf("skip_pivs of len=%d: ",ans->length);
for(int i=0; i< ans->length; i++)
printf(" %d%s",ans->values[i],i+1 == ans->length ?"\n":"");
printf("pivs of len=%d, rank=%zu: ",pivs->length, rank);
for(size_t i=0; i< rank; i++)
printf(" %d%s",pivs->values[i],i+1 == rank ?"\n":"");
}
#endif
free(arr);
return ans;
}


/** @brief Random Information Set search for small-E logical operators.
*
* @param dW weight increment from the minimum found
Expand Down
21 changes: 12 additions & 9 deletions src/makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
WARN = -Wall -Wsign-compare -Wextra
# use `valgrind` for memory / array bounds check
# use `-ggdb3` for use with valgrind
# use `-ggdb3` for use with `valgrind`
# use `-pg` switch for use with `gprof` (profiling/performance analyzer)
## EXTRA may be set on the command line, e.g., "EXTRA=''" or "EXTRA='-pg -DNDEBUG'"
# EXTRA = -DNDEBUG -Wno-unused-variable -Wno-unused-parameter
# OPT = -g -march=native -mtune=native -O3 ${PRODUCTION}
EXTRA=-DNDEBUG
# use -DNDEBUG to disable assert, -Wfatal-errors to stop at 1st error
# to compile on Mac you may need to disable '-march=native`
OPT = -g -march=native -mtune=native -O3 ${EXTRA}
OPT = -g -march=native -mtune=native -O3
#OPT = -g -mtune=native -O3 ${EXTRA}
CC = gcc
CFLAGS = ${OPT} ${VER} ${WARN}
CFLAGS = ${OPT} ${VER} ${WARN} ${EXTRA}
CPP = g++

default: give_help
Expand Down Expand Up @@ -49,15 +50,17 @@ zip: ${src}
zip -9 -o dist_m4ri.zip ${src} ../Doxyfile ../README.md

give_help:
@echo "\e[36m make dist_m4ri \e[0m" " to compile \`dist_m4ri\` \e[32m\e[0m"
@echo "\e[36m make clean \e[0m " "to\e[31m remove\e[0m object files and such"
@echo "\e[36m make veryclean \e[0m" "also\e[31m remove\e[0m executables and zip file"
@echo "\e[36m make zip \e[0m " "to make \e[35m \`dist_m4ri.zip\`\e[0m file with all sources"
@echo "\e[36m make tags \e[0m " "to create \e[35m TAGS\e[0m file"
@echo "\e[36m make -j dist_m4ri \e[0m" "\t\t compile \`dist_m4ri\` \e[32m\e[0m"
@echo "\e[36m make -j dist_m4ri EXTRA=\"\"\e[0m" "\t compile with add'l checks / assert statements\e[32m\e[0m"
@echo "\e[36m make -j dist_m4ri OPT=\"-pg -O2\"\e[0m" "\t compile for use with \`gprof\`\e[32m\e[0m"
@echo "\e[36m make clean \e[0m " "\t to\e[31m remove\e[0m object files and such"
@echo "\e[36m make veryclean \e[0m" "\t also\e[31m remove\e[0m executables and zip file"
@echo "\e[36m make zip \e[0m " "\t to make \e[35m \`dist_m4ri.zip\`\e[0m file with all sources"
@echo "\e[36m make tags \e[0m " "\t to create \e[35m TAGS\e[0m file"
@echo
@echo "\e[31m The program does not compile?\e[0m"
@echo " - Make sure you have '\e[32mlibm4ri_dev\e[0m' on your system."
@echo " Please see '../README.md' for installation instructions."
@echo " - On a Mac, you may want to disable '\e[32m-march=native\e[0m' compiler switch by running"
@echo "\e[36m make dist_m4ri OPT='-g -mtune=native -O3'\e[0m"
@echo "\t\e[36m make dist_m4ri OPT='-g -mtune=native -O3'\e[0m"

0 comments on commit 1b3d7c3

Please sign in to comment.