Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions .github/workflows/msolve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,39 @@ on:
jobs:
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
include:
- { os: ubuntu-latest, shell: bash }
- { os: macos-latest, shell: bash }
- { os: windows-latest, shell: msys2 }
defaults:
run:
shell: ${{ matrix.shell }} {0}
steps:
- name: Disable CRLF conversion on Windows
if: runner.os == 'Windows'
shell: pwsh
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v3
- name: Set up MSYS2
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
update: true
- name: "Install dependencies"
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
# sharutils is for uudecode
sudo apt install libgmp-dev libflint-dev libmpfr-dev libntl-dev
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install autoconf automake libtool gmp flint mpfr ntl
elif [ "$RUNNER_OS" == "Windows" ]; then
pacman -S --noconfirm autotools mingw-w64-x86_64-toolchain mingw-w64-x86_64-gmp mingw-w64-x86_64-flint mingw-w64-x86_64-mpfr mingw-w64-x86_64-ntl
else
echo "$RUNNER_OS not supported"
exit 1
Expand All @@ -33,7 +50,7 @@ jobs:
run: ./autogen.sh
- name: configure
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
if [ "$RUNNER_OS" = "Linux" ] || [ "$RUNNER_OS" = "Windows" ]; then
./configure
elif [ "$RUNNER_OS" == "macOS" ]; then
./configure LDFLAGS="-L$(brew --prefix)/lib/" CFLAGS="-g -O2 -I$(brew --prefix)/include/"
Expand All @@ -47,7 +64,7 @@ jobs:
run: make check
- name: make distcheck
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
if [ "$RUNNER_OS" = "Linux" ] || [ "$RUNNER_OS" = "Windows" ]; then
make distcheck
elif [ "$RUNNER_OS" == "macOS" ]; then
make distcheck LDFLAGS="-L$(brew --prefix)/lib/" CFLAGS="-g -O2 -I$(brew --prefix)/include/"
Expand Down
1 change: 1 addition & 0 deletions src/fglm/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ libfglm_la_CFLAGS = $(SIMD_FLAGS) $(CPUEXT_FLAGS) $(OPENMP_CFLAGS)

EXTRA_DIST = fglm.h \
libfglm.h \
aligned_alloc.h \
berlekamp_massey.c \
data_fglm.c \
fglm_core.c \
Expand Down
50 changes: 50 additions & 0 deletions src/fglm/aligned_alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* This file is part of msolve.
*
* msolve is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* msolve is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with msolve. If not, see <https://www.gnu.org/licenses/>
*
* Authors:
* Jérémy Berthomieu
* Christian Eder
* Mohab Safey El Din */

#ifndef ALIGNED_ALLOC_HEADER_H
#define ALIGNED_ALLOC_HEADER_H

#ifdef _WIN32

#include <errno.h>
#include <malloc.h>

static inline int posix_memalign(void **__memptr, size_t __alignment, size_t __size)
{
void *p = _aligned_malloc(__size, __alignment);
if (!p)
{
return ENOMEM;
}
*__memptr = p;
return 0;
}
#endif

static inline void posix_memalign_free(void *__p)
{
#ifdef _WIN32
_aligned_free(__p);
#else
free(__p);
#endif
}

#endif /* ALIGNED_ALLOC_HEADER_H */
19 changes: 10 additions & 9 deletions src/fglm/data_fglm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
#include <flint/nmod_poly_factor.h>
#include <flint/ulong_extras.h>

#include "aligned_alloc.h"

static inline void free_sp_mat_fglm(sp_matfglm_t *mat){
if(mat!=NULL){
free(mat->dense_mat);
free(mat->triv_idx);
free(mat->triv_pos);
free(mat->dense_idx);
free(mat->dst);
posix_memalign_free(mat->dense_mat);
posix_memalign_free(mat->triv_idx);
posix_memalign_free(mat->triv_pos);
posix_memalign_free(mat->dense_idx);
posix_memalign_free(mat->dst);
free(mat);
}
}
Expand Down Expand Up @@ -80,10 +81,10 @@ static inline fglm_data_t *allocate_fglm_data(szmat_t nrows, szmat_t ncols, szma


static inline void free_fglm_data(fglm_data_t *data){
free(data->vecinit);
free(data->res);
free(data->vecmult);
free(data->vvec);
posix_memalign_free(data->vecinit);
posix_memalign_free(data->res);
posix_memalign_free(data->vecmult);
posix_memalign_free(data->vvec);
free(data->pts);
free(data);
}
Expand Down
14 changes: 8 additions & 6 deletions src/fglm/fglm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ double omp_get_wtime(void) { return realtime();}
#include "../upolmat/nmod_poly_mat_pmbasis.c"
#endif

#include "aligned_alloc.h"

void print_fglm_data(
FILE *file,
const md_t * const st,
Expand Down Expand Up @@ -775,9 +777,9 @@ static void generate_matrix_sequence(sp_matfglm_t *matxn, fglm_data_t *data,
RED_32,
RED_64);
}
free(Rmat);
free(res);
free(tres);
posix_memalign_free(Rmat);
posix_memalign_free(res);
posix_memalign_free(tres);

}

Expand Down Expand Up @@ -1544,7 +1546,7 @@ param_t *nmod_fglm_compute_trace_data(sp_matfglm_t *matrix, mod_t prime,
#endif

#if DEBUGFGLM >= 1
FILE *fmat = fopen("/tmp/matrix.fglm", "w");
FILE *fmat = fopen("/tmp/matrix.fglm", "wb");
display_fglm_matrix(fmat, matrix);
fclose(fmat);
#endif
Expand Down Expand Up @@ -1749,7 +1751,7 @@ int nmod_fglm_compute_apply_trace_data(sp_matfglm_t *matrix,
#endif

#if DEBUGFGLM >= 1
FILE *fmat = fopen("/tmp/matrix.fglm", "w");
FILE *fmat = fopen("/tmp/matrix.fglm", "wb");
display_fglm_matrix(fmat, matrix);
fclose(fmat);
#endif
Expand Down Expand Up @@ -2098,7 +2100,7 @@ param_t *nmod_fglm_guess_colon(sp_matfglmcol_t *matrix,
#endif

#if DEBUGFGLM >= 1
FILE *fmat = fopen("/tmp/matrix.fglm", "w");
FILE *fmat = fopen("/tmp/matrix.fglm", "wb");
display_fglm_colon_matrix(fmat, matrix);
fclose(fmat);
#endif
Expand Down
1 change: 1 addition & 0 deletions src/msolve/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ libmsolve_la_LIBADD = ../usolve/libusolve.la ../fglm/libfglm.la ../neogb/libneo

EXTRA_DIST = msolve-data.h \
msolve.h \
getdelim.h \
msolve-data.c \
duplicate.c \
hilbert.c \
Expand Down
2 changes: 1 addition & 1 deletion src/msolve/duplicate.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ static inline void duplicate_data_mthread_gbtrace(int nthreads,
trace_t **btrace){


const len_t len = num_gb[0] * (st->nvars);
const len_t len = num_gb[0] * (st->nvars - st->nev);

for(int i = 0; i < nthreads; i++){
leadmons_current[i] = (int32_t *)calloc(len, sizeof(int32_t));
Expand Down
131 changes: 131 additions & 0 deletions src/msolve/getdelim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* getdelim.h --- Implementation of replacement getdelim/getline function.
Copyright (C) 1994, 1996-1998, 2001, 2003, 2005-2025 Free Software
Foundation, Inc.

This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.

This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */

/* Ported from glibc by Simon Josefsson. */

#ifndef GETDELIM_HEADER_H
#define GETDELIM_HEADER_H

#ifdef _WIN32

#include <stdio.h>

#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>

static inline void
alloc_failed (void)
{
#if defined _WIN32 && ! defined __CYGWIN__
/* Avoid errno problem without using the realloc module; see:
https://lists.gnu.org/r/bug-gnulib/2016-08/msg00025.html */
errno = ENOMEM;
#endif
}

/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
NULL), pointing to *N characters of space. It is realloc'ed as
necessary. Returns the number of characters read (not including
the null terminator), or -1 on error or EOF. */

static inline ssize_t
getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
{
ssize_t result;
size_t cur_len = 0;

if (lineptr == NULL || n == NULL || fp == NULL)
{
errno = EINVAL;
return -1;
}

if (*lineptr == NULL || *n == 0)
{
char *new_lineptr;
*n = 120;
new_lineptr = (char *) realloc (*lineptr, *n);
if (new_lineptr == NULL)
{
alloc_failed ();
return -1;
}
*lineptr = new_lineptr;
}

for (;;)
{
int i;

i = getc (fp);
if (i == EOF)
{
result = -1;
break;
}

/* Make enough space for len+1 (for final NUL) bytes. */
if (cur_len + 1 >= *n)
{
size_t needed_max =
SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
size_t needed = 2 * *n + 1; /* Be generous. */
char *new_lineptr;

if (needed_max < needed)
needed = needed_max;
if (cur_len + 1 >= needed)
{
errno = EOVERFLOW;
return -1;
}

new_lineptr = (char *) realloc (*lineptr, needed);
if (new_lineptr == NULL)
{
alloc_failed ();
return -1;
}

*lineptr = new_lineptr;
*n = needed;
}

(*lineptr)[cur_len] = i;
cur_len++;

if (i == delimiter)
break;
}
(*lineptr)[cur_len] = '\0';
result = cur_len ? cur_len : result;

return result;
}

static inline ssize_t
getline (char **lineptr, size_t *n, FILE *stream)
{
return getdelim (lineptr, n, '\n', stream);
}

#endif

#endif /* GETDELIM_HEADER_H */
Loading
Loading