Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for building with mingw #35796

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Patch cliquer to allow building on Windows
See reasoning for patching cliquer at the top of the patch file.
  • Loading branch information
pranavrajpal committed Jun 19, 2023
commit 9f9bf497428f54cc29244f468a34ba7961ab3859
238 changes: 238 additions & 0 deletions build/pkgs/cliquer/patches/remove-cputime.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
Cliquer fails to compile on mingw due to the use of the POSIX-specific sys/times.h. Since
sys/times.h is only getting used to measure the CPU time elapsed for various operations, and
sagemath doesn't appear to use that, removing the relevant lines and just replacing the elapsed
CPU time with 0 gets cliquer to build.

diff --git a/lib/cliquer.c b/lib/cliquer.c
index 49d0ad5..20b259c 100644
--- a/lib/cliquer.c
+++ b/lib/cliquer.c
@@ -11,7 +11,6 @@
#include <limits.h>
#include <unistd.h>
#include <sys/time.h>
-#include <sys/times.h>

#include "cliquer/cliquer.h"

@@ -33,7 +32,6 @@ clique_options *clique_default_options=&clique_default_options_struct;
static int *clique_size; /* c[i] == max. clique size in {0,1,...,i-1} */
static set_t current_clique; /* Current clique being searched. */
static set_t best_clique; /* Largest/heaviest clique found so far. */
-static struct tms cputimer; /* Timer for opts->time_function() */
static struct timeval realtimer; /* Timer for opts->time_function() */
static int clique_list_count=0; /* No. of cliques in opts->clique_list[] */
static int weight_multiplier=1; /* Weights multiplied by this when passing
@@ -60,9 +58,7 @@ int old_clique_list_count = clique_list_count; \
int old_weight_multiplier = weight_multiplier; \
int **old_temp_list = temp_list; \
int old_temp_count = temp_count; \
-struct tms old_cputimer; \
struct timeval old_realtimer; \
-memcpy(&old_cputimer,&cputimer,sizeof(struct tms)); \
memcpy(&old_realtimer,&realtimer,sizeof(struct timeval));

#define ENTRANCE_RESTORE() \
@@ -73,12 +69,10 @@ clique_list_count = old_clique_list_count; \
weight_multiplier = old_weight_multiplier; \
temp_list = old_temp_list; \
temp_count = old_temp_count; \
-memcpy(&cputimer,&old_cputimer,sizeof(struct tms)); \
memcpy(&realtimer,&old_realtimer,sizeof(struct timeval));


/* Number of clock ticks per second (as returned by sysconf(_SC_CLK_TCK)) */
-static int clocks_per_sec=0;



@@ -138,7 +132,6 @@ static boolean false_function(set_t clique,graph_t *g,clique_options *opts);
*/
static int unweighted_clique_search_single(int *table, int min_size,
graph_t *g, clique_options *opts) {
- struct tms tms;
struct timeval timeval;
int i,j;
int v,w;
@@ -179,13 +172,10 @@ static int unweighted_clique_search_single(int *table, int min_size,

if (opts && opts->time_function) {
gettimeofday(&timeval,NULL);
- times(&tms);
if (!opts->time_function(entrance_level,
i+1,g->n,clique_size[v] *
weight_multiplier,
- (double)(tms.tms_utime-
- cputimer.tms_utime)/
- clocks_per_sec,
+ 0,
timeval.tv_sec-
realtimer.tv_sec+
(double)(timeval.tv_usec-
@@ -335,7 +325,6 @@ static int unweighted_clique_search_all(int *table, int start,
boolean maximal, graph_t *g,
clique_options *opts) {
struct timeval timeval;
- struct tms tms;
int i,j;
int v;
int *newtable;
@@ -376,13 +365,10 @@ static int unweighted_clique_search_all(int *table, int start,

if (opts->time_function) {
gettimeofday(&timeval,NULL);
- times(&tms);
if (!opts->time_function(entrance_level,
i+1,g->n,min_size *
weight_multiplier,
- (double)(tms.tms_utime-
- cputimer.tms_utime)/
- clocks_per_sec,
+ 0,
timeval.tv_sec-
realtimer.tv_sec+
(double)(timeval.tv_usec-
@@ -539,7 +525,6 @@ static int weighted_clique_search_single(int *table, int min_weight,
int max_weight, graph_t *g,
clique_options *opts) {
struct timeval timeval;
- struct tms tms;
int i,j;
int v;
int *newtable;
@@ -629,13 +614,10 @@ static int weighted_clique_search_single(int *table, int min_weight,

if (opts->time_function) {
gettimeofday(&timeval,NULL);
- times(&tms);
if (!opts->time_function(entrance_level,
i+1,g->n,clique_size[v] *
weight_multiplier,
- (double)(tms.tms_utime-
- cputimer.tms_utime)/
- clocks_per_sec,
+ 0,
timeval.tv_sec-
realtimer.tv_sec+
(double)(timeval.tv_usec-
@@ -687,7 +669,6 @@ static int weighted_clique_search_all(int *table, int start,
boolean maximal, graph_t *g,
clique_options *opts) {
struct timeval timeval;
- struct tms tms;
int i,j;
int v;
int *newtable;
@@ -730,13 +711,10 @@ static int weighted_clique_search_all(int *table, int start,

if (opts->time_function) {
gettimeofday(&timeval,NULL);
- times(&tms);
if (!opts->time_function(entrance_level,
i+1,g->n,clique_size[v] *
weight_multiplier,
- (double)(tms.tms_utime-
- cputimer.tms_utime)/
- clocks_per_sec,
+ 0,
timeval.tv_sec-
realtimer.tv_sec+
(double)(timeval.tv_usec-
@@ -1106,9 +1084,6 @@ set_t clique_unweighted_find_single(graph_t *g,int min_size,int max_size,
return NULL;
}

- if (clocks_per_sec==0)
- clocks_per_sec=sysconf(_SC_CLK_TCK);
- ASSERT(clocks_per_sec>0);

/* Dynamic allocation */
current_clique=set_new(g->n);
@@ -1119,7 +1094,6 @@ set_t clique_unweighted_find_single(graph_t *g,int min_size,int max_size,

/* "start clock" */
gettimeofday(&realtimer,NULL);
- times(&cputimer);

/* reorder */
if (opts->reorder_function) {
@@ -1230,9 +1204,6 @@ int clique_unweighted_find_all(graph_t *g, int min_size, int max_size,
return 0;
}

- if (clocks_per_sec==0)
- clocks_per_sec=sysconf(_SC_CLK_TCK);
- ASSERT(clocks_per_sec>0);

/* Dynamic allocation */
current_clique=set_new(g->n);
@@ -1246,7 +1217,6 @@ int clique_unweighted_find_all(graph_t *g, int min_size, int max_size,

/* "start clock" */
gettimeofday(&realtimer,NULL);
- times(&cputimer);

/* reorder */
if (opts->reorder_function) {
@@ -1380,9 +1350,6 @@ set_t clique_find_single(graph_t *g,int min_weight,int max_weight,
return NULL;
}

- if (clocks_per_sec==0)
- clocks_per_sec=sysconf(_SC_CLK_TCK);
- ASSERT(clocks_per_sec>0);

/* Check whether we can use unweighted routines. */
if (!graph_weighted(g)) {
@@ -1417,7 +1384,6 @@ set_t clique_find_single(graph_t *g,int min_weight,int max_weight,

/* "start clock" */
gettimeofday(&realtimer,NULL);
- times(&cputimer);

/* reorder */
if (opts->reorder_function) {
@@ -1539,9 +1505,6 @@ int clique_find_all(graph_t *g, int min_weight, int max_weight,
return 0;
}

- if (clocks_per_sec==0)
- clocks_per_sec=sysconf(_SC_CLK_TCK);
- ASSERT(clocks_per_sec>0);

if (!graph_weighted(g)) {
min_weight=DIV_UP(min_weight,g->weights[0]);
@@ -1573,7 +1536,6 @@ int clique_find_all(graph_t *g, int min_weight, int max_weight,

/* "start clock" */
gettimeofday(&realtimer,NULL);
- times(&cputimer);

/* reorder */
if (opts->reorder_function) {
diff --git a/lib/reorder.c b/lib/reorder.c
index 9ec127d..ea9f8f9 100644
--- a/lib/reorder.c
+++ b/lib/reorder.c
@@ -9,7 +9,6 @@
#include "cliquer/reorder.h"

#include <time.h>
-#include <sys/times.h>
#include <stdlib.h>

#include <limits.h>
@@ -406,12 +405,11 @@ int *reorder_by_degree(graph_t *g, boolean weighted) {
* is called using the system time.
*/
int *reorder_by_random(graph_t *g, boolean weighted) {
- struct tms t;
int i,r;
int *new;
boolean *used;

- srand(times(&t)+time(NULL));
+ srand(time(NULL));

new=calloc(g->n, sizeof(int));
used=calloc(g->n, sizeof(boolean));