Ticket #5623 (closed enhancement: fixed)

Opened 4 years ago

Last modified 4 years ago

[with patch, positive review] 5x speedup in all_graph_colorings

Reported by: carlohamalainen Owned by: boothby
Priority: minor Milestone: sage-3.4.1
Component: graph theory Keywords:
Cc: Work issues:
Report Upstream: Reviewers:
Authors: Merged in:
Dependencies: Stopgaps:

Description (last modified by mabshoff) (diff)

This patch changes all_graph_colorings to use the C++ dancing links implementation instead of the Cython implementation.

  • sage -testall is all ok
  • valgrind is ok
  • Roughly 5x speedup on some random graphs (see test.sage):

Sage 3.4 timing:

carlo@ka37:~/work/code/graphdlx$ sage test.sage 
5 loops, best of 3: 158 ms per loop
carlo@ka37:~/work/code/graphdlx$ sage test.sage 
5 loops, best of 3: 158 ms per loop
carlo@ka37:~/work/code/graphdlx$ sage test.sage 
5 loops, best of 3: 157 ms per loop

Sage 3.4 with patch timing:

5 loops, best of 3: 33.5 ms per loop
carlo@ka37:~/work/code/graphdlx$ sage test.sage 
5 loops, best of 3: 33.1 ms per loop
carlo@ka37:~/work/code/graphdlx$ sage test.sage 
5 loops, best of 3: 33.3 ms per loop

Attachments

test.sage Download (1.0 KB) - added by carlohamalainen 4 years ago.
graphcoloring_5623_test.patch Download (2.8 KB) - added by boothby 4 years ago.
graphcolouring.patch Download (2.1 KB) - added by carlohamalainen 4 years ago.
dlxcpp.patch Download (645 bytes) - added by carlohamalainen 4 years ago.
graphcoloring_5623_doctests.patch Download (874 bytes) - added by boothby 4 years ago.

Change History

Changed 4 years ago by carlohamalainen

comment:1 Changed 4 years ago by boothby

  • Summary changed from 5x speedup in all_graph_colorings to [with patch, partial positive review] 5x speedup in all_graph_colorings

Works for me. I'd like to see the test.sage file be reworked into a Test class for randomized testing. search_src('class Test') for examples.

comment:2 Changed 4 years ago by boothby

  • Summary changed from [with patch, partial positive review] 5x speedup in all_graph_colorings to [with patch, negative review] 5x speedup in all_graph_colorings

OOps.

sage: g = Graph()
sage: c = 0
sage: for h in graph_coloring.all_graph_colorings(g,0,False): c+=1
------------------------------------------------------------
Unhandled SIGSEGV: A segmentation fault occured in SAGE.
This probably occured because a *compiled* component
of SAGE has a bug in it (typically accessing invalid memory)
or is not properly wrapped with _sig_on, _sig_off.
You might want to run SAGE under gdb with 'sage -gdb' to debug this.
SAGE will now terminate (sorry).
------------------------------------------------------------

Changed 4 years ago by boothby

comment:3 Changed 4 years ago by boothby

The attachment 'graphcoloring_5623_test.patch' implements a Test class that does randomized testing. Fix the segfault, and I'll be happy with it.

Changed 4 years ago by carlohamalainen

Changed 4 years ago by carlohamalainen

comment:4 Changed 4 years ago by carlohamalainen

  • Summary changed from [with patch, negative review] 5x speedup in all_graph_colorings to [with patch, needs review] 5x speedup in all_graph_colorings

I updated graphcolouring.patch:

  • returns immediately when n == 0
  • raises a ValueError? if n < 0

The patch dlxcpp.patch fixes the segfault on an empty graph.

comment:5 Changed 4 years ago by mabshoff

Could you please specify exactly which patches need to be applied and reviewed?

Cheers,

Michael

comment:6 Changed 4 years ago by mabshoff

Could you please specify exactly which patches need to be applied and reviewed?

Cheers,

Michael

comment:7 Changed 4 years ago by carlohamalainen

All three patches should be applied:

  • graphcoloring_5623_test.patch
  • graphcolouring.patch
  • dlxcpp.patch

The final patch is new and I guess should be reviewed (it's just a one-liner).

Changed 4 years ago by boothby

comment:8 Changed 4 years ago by boothby

  • Summary changed from [with patch, needs review] 5x speedup in all_graph_colorings to [with patch, positive review] 5x speedup in all_graph_colorings

I've added one more patch which tests for the previous segfault, and negative entries. The patches work when applied in the order:

  • graphcolouring.patch
  • dlxcpp.patch
  • graphcoloring_5623_test.patch
  • graphcoloring_5623_doctests.patch

comment:9 Changed 4 years ago by mabshoff

  • Status changed from new to closed
  • Resolution set to fixed

Merged

  • graphcolouring.patch
  • dlxcpp.patch
  • graphcoloring_5623_test.patch
  • graphcoloring_5623_doctests.patch

in Sage 3.4.1.rc0.

Cheers,

Michael

comment:10 Changed 4 years ago by mabshoff

  • Description modified (diff)
Note: See TracTickets for help on using tickets.