Skip to content

Commit 6c26857

Browse files
authored
Merge pull request #214 from wegank/port-to-windows-0
2 parents 0978554 + 8f851e8 commit 6c26857

12 files changed

Lines changed: 329 additions & 104 deletions

File tree

.github/workflows/msolve.yml

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,37 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
os:
17-
- ubuntu-latest
18-
- macos-latest
19-
- macos-26-intel
16+
include:
17+
- { os: ubuntu-latest, shell: bash }
18+
- { os: macos-latest, shell: bash }
19+
- { os: macos-26-intel, shell: bash }
20+
- { os: windows-latest, shell: msys2 }
21+
defaults:
22+
run:
23+
shell: ${{ matrix.shell }} {0}
2024
steps:
25+
- name: Disable CRLF conversion on Windows
26+
if: runner.os == 'Windows'
27+
shell: pwsh
28+
run: |
29+
git config --global core.autocrlf false
30+
git config --global core.eol lf
2131
- uses: actions/checkout@v6
32+
- name: Set up MSYS2
33+
if: runner.os == 'Windows'
34+
uses: msys2/setup-msys2@v2
35+
with:
36+
msystem: UCRT64
37+
update: true
2238
- name: "Install dependencies"
2339
run: |
2440
if [ "$RUNNER_OS" == "Linux" ]; then
2541
# sharutils is for uudecode
2642
sudo apt install libgmp-dev libflint-dev libmpfr-dev libntl-dev
2743
elif [ "$RUNNER_OS" == "macOS" ]; then
2844
brew install autoconf automake libtool gmp flint mpfr ntl
45+
elif [ "$RUNNER_OS" == "Windows" ]; then
46+
pacman -S --noconfirm autotools mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86_64-gmp mingw-w64-ucrt-x86_64-flint mingw-w64-ucrt-x86_64-mpfr mingw-w64-ucrt-x86_64-ntl
2947
else
3048
echo "$RUNNER_OS not supported"
3149
exit 1
@@ -34,7 +52,7 @@ jobs:
3452
run: ./autogen.sh
3553
- name: configure
3654
run: |
37-
if [ "$RUNNER_OS" == "Linux" ]; then
55+
if [ "$RUNNER_OS" == "Linux" ] || [ "$RUNNER_OS" == "Windows" ]; then
3856
./configure
3957
elif [ "$RUNNER_OS" == "macOS" ]; then
4058
./configure LDFLAGS="-L$(brew --prefix)/lib/" \
@@ -52,7 +70,7 @@ jobs:
5270
run: cat test-suite.log || true
5371
- name: make distcheck
5472
run: |
55-
if [ "$RUNNER_OS" == "Linux" ]; then
73+
if [ "$RUNNER_OS" == "Linux" ] || [ "$RUNNER_OS" == "Windows" ]; then
5674
make distcheck
5775
elif [ "$RUNNER_OS" == "macOS" ]; then
5876
make distcheck LDFLAGS="-L$(brew --prefix)/lib/" \
@@ -67,22 +85,41 @@ jobs:
6785

6886
build-fixed-seed:
6987
runs-on: ${{ matrix.os }}
70-
timeout-minutes: 10
88+
timeout-minutes: 20
7189
strategy:
7290
fail-fast: false
7391
matrix:
74-
os:
75-
- ubuntu-latest
76-
- macos-latest
92+
include:
93+
- { os: ubuntu-latest, shell: bash }
94+
- { os: macos-latest, shell: bash }
95+
- { os: macos-26-intel, shell: bash }
96+
- { os: windows-latest, shell: msys2 }
97+
defaults:
98+
run:
99+
shell: ${{ matrix.shell }} {0}
77100
steps:
101+
- name: Disable CRLF conversion on Windows
102+
if: runner.os == 'Windows'
103+
shell: pwsh
104+
run: |
105+
git config --global core.autocrlf false
106+
git config --global core.eol lf
78107
- uses: actions/checkout@v6
108+
- name: Set up MSYS2
109+
if: runner.os == 'Windows'
110+
uses: msys2/setup-msys2@v2
111+
with:
112+
msystem: UCRT64
113+
update: true
79114
- name: "Install dependencies"
80115
run: |
81116
if [ "$RUNNER_OS" == "Linux" ]; then
82117
# sharutils is for uudecode
83118
sudo apt install libgmp-dev libflint-dev libmpfr-dev libntl-dev
84119
elif [ "$RUNNER_OS" == "macOS" ]; then
85120
brew install autoconf automake libtool gmp flint mpfr ntl
121+
elif [ "$RUNNER_OS" == "Windows" ]; then
122+
pacman -S --noconfirm autotools mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86_64-gmp mingw-w64-ucrt-x86_64-flint mingw-w64-ucrt-x86_64-mpfr mingw-w64-ucrt-x86_64-ntl
86123
else
87124
echo "$RUNNER_OS not supported"
88125
exit 1
@@ -91,7 +128,7 @@ jobs:
91128
run: ./autogen.sh
92129
- name: configure
93130
run: |
94-
if [ "$RUNNER_OS" == "Linux" ]; then
131+
if [ "$RUNNER_OS" == "Linux" ] || [ "$RUNNER_OS" == "Windows" ]; then
95132
./configure
96133
elif [ "$RUNNER_OS" == "macOS" ]; then
97134
./configure LDFLAGS="-L$(brew --prefix)/lib/" \
@@ -109,7 +146,7 @@ jobs:
109146
run: cat test-suite.log || true
110147
- name: make distcheck with fixed seed
111148
run: |
112-
if [ "$RUNNER_OS" == "Linux" ]; then
149+
if [ "$RUNNER_OS" == "Linux" ] || [ "$RUNNER_OS" == "Windows" ]; then
113150
make distcheck DISTCHECK_CONFIGURE_FLAGS="SEED=1617753600"
114151
elif [ "$RUNNER_OS" == "macOS" ]; then
115152
make distcheck LDFLAGS="-L$(brew --prefix)/lib/" \

src/fglm/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ libfglm_la_CFLAGS = $(SIMD_FLAGS) $(CPUEXT_FLAGS) $(OPENMP_CFLAGS) -Wall -Wextr
66

77
EXTRA_DIST = fglm.h \
88
libfglm.h \
9+
aligned_alloc.h \
910
berlekamp_massey.c \
1011
data_fglm.c \
1112
fglm_core.c \

src/fglm/aligned_alloc.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* This file is part of msolve.
2+
*
3+
* msolve is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* msolve is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with msolve. If not, see <https://www.gnu.org/licenses/>
15+
*
16+
* Authors:
17+
* Jérémy Berthomieu
18+
* Christian Eder
19+
* Mohab Safey El Din */
20+
21+
#ifndef ALIGNED_ALLOC_HEADER_H
22+
#define ALIGNED_ALLOC_HEADER_H
23+
24+
#ifdef _WIN32
25+
26+
#include <errno.h>
27+
#include <malloc.h>
28+
29+
static inline int posix_memalign(void **__memptr, size_t __alignment, size_t __size)
30+
{
31+
void *p = _aligned_malloc(__size, __alignment);
32+
if (!p)
33+
{
34+
return ENOMEM;
35+
}
36+
*__memptr = p;
37+
return 0;
38+
}
39+
#endif
40+
41+
static inline void posix_memalign_free(void *__p)
42+
{
43+
#ifdef _WIN32
44+
_aligned_free(__p);
45+
#else
46+
free(__p);
47+
#endif
48+
}
49+
50+
#endif /* ALIGNED_ALLOC_HEADER_H */

src/fglm/data_fglm.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
#include <flint/ulong_extras.h>
2828
#include "../msolve/streams.h"
2929

30+
#include "aligned_alloc.h"
3031

3132
static inline void free_sp_mat_fglm(sp_matfglm_t *mat){
3233
if(mat!=NULL){
33-
free(mat->dense_mat);
34-
free(mat->triv_idx);
35-
free(mat->triv_pos);
36-
free(mat->dense_idx);
37-
free(mat->dst);
34+
posix_memalign_free(mat->dense_mat);
35+
posix_memalign_free(mat->triv_idx);
36+
posix_memalign_free(mat->triv_pos);
37+
posix_memalign_free(mat->dense_idx);
38+
posix_memalign_free(mat->dst);
3839
free(mat);
3940
}
4041
}
@@ -81,10 +82,10 @@ static inline fglm_data_t *allocate_fglm_data(szmat_t nrows, szmat_t ncols, szma
8182

8283

8384
static inline void free_fglm_data(fglm_data_t *data){
84-
free(data->vecinit);
85-
free(data->res);
86-
free(data->vecmult);
87-
free(data->vvec);
85+
posix_memalign_free(data->vecinit);
86+
posix_memalign_free(data->res);
87+
posix_memalign_free(data->vecmult);
88+
posix_memalign_free(data->vvec);
8889
free(data->pts);
8990
free(data);
9091
}

src/fglm/fglm_core.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ double omp_get_wtime(void) { return realtime();}
7272
#include "../upolmat/nmod_poly_mat_pmbasis.c"
7373
#endif
7474

75+
#include "aligned_alloc.h"
76+
7577
void print_fglm_data(
7678
FILE *file,
7779
const md_t * const st,
@@ -614,9 +616,9 @@ static void generate_matrix_sequence(sp_matfglm_t *matxn, fglm_data_t *data,
614616
exit(1);
615617
#endif
616618
}
617-
free(Rmat);
618-
free(res);
619-
free(tres);
619+
posix_memalign_free(Rmat);
620+
posix_memalign_free(res);
621+
posix_memalign_free(tres);
620622

621623
}
622624
#endif
@@ -1338,7 +1340,7 @@ param_t *nmod_fglm_compute_trace_data(sp_matfglm_t *matrix, mod_t prime,
13381340
#endif
13391341

13401342
#if DEBUGFGLM >= 1
1341-
FILE *fmat = fopen("/tmp/matrix.fglm", "w");
1343+
FILE *fmat = fopen("/tmp/matrix.fglm", "wb");
13421344
display_fglm_matrix(fmat, matrix);
13431345
fclose(fmat);
13441346
#endif
@@ -1540,7 +1542,7 @@ int nmod_fglm_compute_apply_trace_data(sp_matfglm_t *matrix,
15401542
#endif
15411543

15421544
#if DEBUGFGLM >= 1
1543-
FILE *fmat = fopen("/tmp/matrix.fglm", "w");
1545+
FILE *fmat = fopen("/tmp/matrix.fglm", "wb");
15441546
display_fglm_matrix(fmat, matrix);
15451547
fclose(fmat);
15461548
#endif
@@ -1759,7 +1761,7 @@ param_t *nmod_fglm_guess_colon(sp_matfglmcol_t *matrix,
17591761
#endif
17601762

17611763
#if DEBUGFGLM >= 1
1762-
FILE *fmat = fopen("/tmp/matrix.fglm", "w");
1764+
FILE *fmat = fopen("/tmp/matrix.fglm", "wb");
17631765
display_fglm_colon_matrix(fmat, matrix);
17641766
fclose(fmat);
17651767
#endif

src/msolve/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ libmsolve_la_LIBADD = ../usolve/libusolve.la ../fglm/libfglm.la ../neogb/libneo
88

99
EXTRA_DIST = msolve-data.h \
1010
msolve.h \
11+
getdelim.h \
1112
msolve-data.c \
1213
duplicate.c \
1314
hilbert.c \

0 commit comments

Comments
 (0)