Merge lp:~verifypn-cpn/verifypn/SuccGen-simp into lp:verifypn

Proposed by Andreas Klostergaard
Status: Work in progress
Proposed branch: lp:~verifypn-cpn/verifypn/SuccGen-simp
Merge into: lp:verifypn
Diff against target: 67 lines (+9/-12)
2 files modified
CMakeLists.txt (+6/-4)
PetriEngine/SuccessorGenerator.cpp (+3/-8)
To merge this branch: bzr merge lp:~verifypn-cpn/verifypn/SuccGen-simp
Reviewer Review Type Date Requested Status
Peter Gjøl Jensen Approve
Review via email: mp+347806@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) wrote :

This gets quite less readable. Does it improve the performance (and how much)?

Revision history for this message
Peter Gjøl Jensen (peter-gjoel) wrote :

I would change the comparison to:

_parent->marking()[inv.place] >= inv.tokens == inv.inhibitor

and add the comment
// Cannot fire if less tokens than weight (and not inhibitor) or more or equal tokens (and inhibitor).

211. By Andreas Klostergaard

Fix from comments

Revision history for this message
Andreas Klostergaard (aklost11) wrote :

> I would change the comparison to:
>
> _parent->marking()[inv.place] >= inv.tokens == inv.inhibitor
>
> and add the comment
> // Cannot fire if less tokens than weight (and not inhibitor) or more or equal
> tokens (and inhibitor).

This should be fixed now. I changed the comment a little, as I found this to make more sense.

Revision history for this message
Andreas Klostergaard (aklost11) wrote :

> This gets quite less readable. Does it improve the performance (and how much)?

It gave about 0.1% performance boost in my tests, but I think it may give more with the changes Peter suggested.

212. By Andreas Klostergaard

Added cmake support for MacOS

Revision history for this message
Peter Gjøl Jensen (peter-gjoel) wrote :

Looks good to me now.

review: Approve
Revision history for this message
Jiri Srba (srba) wrote :

I run correctness checks and this is all fine. There is no noticeable improvement in performance
though. I wonder whether we should merge it to trunk or not. What are the benefits compared to decreased readability?

Revision history for this message
Peter Gjøl Jensen (peter-gjoel) wrote :

> I run correctness checks and this is all fine. There is no noticeable
> improvement in performance
> though. I wonder whether we should merge it to trunk or not. What are the
> benefits compared to decreased readability?

I am abandoning this branch, the code is less readable and any compiler should optimize this away easily.
I am proposing a different merge with the CMAKE changes.

Unmerged revisions

212. By Andreas Klostergaard

Added cmake support for MacOS

211. By Andreas Klostergaard

Fix from comments

210. By Andreas Klostergaard

Simplifying expression in SuccessorGenerator

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2018-04-19 22:14:38 +0000
3+++ CMakeLists.txt 2018-06-14 22:37:21 +0000
4@@ -1,15 +1,19 @@
5 cmake_minimum_required(VERSION 2.8.4)
6 project(verifypn)
7
8-if (UNIX)
9+if (UNIX AND NOT APPLE)
10 if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit?
11 set(ARCH_TYPE "linux64")
12+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -flto -march=x86-64 -std=c++14 -m64 -I.")
13+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto=4 -march=x86-64 -std=c++14 -m64 -static -static-libgcc -static-libstdc++")
14 else()
15 set(ARCH_TYPE "linux32")
16 endif ()
17 elseif(APPLE)
18 if (CMAKE_SIZEOF_VOID_P EQUAL 8) # is system 64-bit?
19 set(ARCH_TYPE "osx64")
20+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7 -std=c++14 -m64 -I. -stdlib=libc++")
21+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -dynamic -mmacosx-version-min=10.7 -std=c++14 -m64 -stdlib=libc++ -lc++")
22 else()
23 set(ARCH_TYPE "osx32")
24 endif ()
25@@ -21,11 +25,9 @@
26 endif()
27 endif ()
28
29-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -flto -march=x86-64 -std=c++14 -m64 -I.")
30 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -pedantic-errors -O2 -DNDEBUG")
31 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
32
33-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto=4 -march=x86-64 -std=c++14 -m64 -static -static-libgcc -static-libstdc++")
34 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -O2 -DNDEBUG")
35 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g")
36
37@@ -38,7 +40,7 @@
38 "**/*.h"
39 "**/**/*.cpp"
40 "**/**/*.h"
41-)
42+ )
43
44 add_executable(verifypn ${verifypn_SRC})
45 target_link_libraries(verifypn ${CMAKE_SOURCE_DIR}/lpsolve/liblpsolve55-${ARCH_TYPE}.a)
46
47=== modified file 'PetriEngine/SuccessorGenerator.cpp'
48--- PetriEngine/SuccessorGenerator.cpp 2018-05-12 15:14:12 +0000
49+++ PetriEngine/SuccessorGenerator.cpp 2018-06-14 22:37:21 +0000
50@@ -57,14 +57,9 @@
51
52 for (; finv < linv; ++finv) {
53 const Invariant& inv = _net._invariants[finv];
54- if ((*_parent).marking()[inv.place] < inv.tokens) {
55- if (!inv.inhibitor) {
56- return false;
57- }
58- } else {
59- if (inv.inhibitor) {
60- return false;
61- }
62+ // Cannot fire if less tokens than weight (when not inhibitor) or more or equal tokens (when inhibitor).
63+ if ((*_parent).marking()[inv.place] >= inv.tokens == inv.inhibitor) {
64+ return false;
65 }
66 }
67 return true;

Subscribers

People subscribed via source and target branches