Commit 0e497373 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Optims]

parent dc1820d0
...@@ -31,10 +31,11 @@ module Gargantext.Prelude ...@@ -31,10 +31,11 @@ module Gargantext.Prelude
) )
where where
import Control.Monad.IO.Class (liftIO, MonadIO)
import Control.Concurrent (newEmptyMVar, takeMVar, putMVar, forkIO)
import GHC.Exts (sortWith) import GHC.Exts (sortWith)
import GHC.Err.Located (undefined) import GHC.Err.Located (undefined)
import GHC.Real (round) import GHC.Real (round)
import Control.Monad.IO.Class (MonadIO)
import Data.Maybe (isJust, fromJust, maybe) import Data.Maybe (isJust, fromJust, maybe)
import Data.Text (Text) import Data.Text (Text)
import Protolude ( Bool(True, False), Int, Int64, Double, Integer import Protolude ( Bool(True, False), Int, Int64, Double, Integer
...@@ -305,3 +306,22 @@ fib n = fib (n-1) + fib (n-2) ...@@ -305,3 +306,22 @@ fib n = fib (n-1) + fib (n-2)
-----------------------------------------------------------------------
-- Memory Optimization
inMVarIO :: MonadIO m => m b -> m b
inMVarIO f = do
mVar <- liftIO newEmptyMVar
zVar <- f
_ <- liftIO $ forkIO $ putMVar mVar zVar
liftIO $ takeMVar mVar
inMVar :: b -> IO b
inMVar f = do
mVar <- newEmptyMVar
let zVar = f
_ <- liftIO $ forkIO $ putMVar mVar zVar
liftIO $ takeMVar mVar
...@@ -99,7 +99,7 @@ getGraph uId nId = do ...@@ -99,7 +99,7 @@ getGraph uId nId = do
newGraph <- liftIO newEmptyMVar newGraph <- liftIO newEmptyMVar
g <- case graph of g <- case graph of
Nothing -> do Nothing -> do
graph' <- computeGraph cId NgramsTerms repo graph' <- inMVarIO $ computeGraph cId NgramsTerms repo
_ <- insertGraph cId uId' (HyperdataGraph $ Just graph') _ <- insertGraph cId uId' (HyperdataGraph $ Just graph')
pure graph' pure graph'
...@@ -134,7 +134,7 @@ computeGraph cId nt repo = do ...@@ -134,7 +134,7 @@ computeGraph cId nt repo = do
<$> groupNodesByNgrams ngs <$> groupNodesByNgrams ngs
<$> getNodesByNgramsOnlyUser cId (lIds <> [lId]) nt (Map.keys ngs) <$> getNodesByNgramsOnlyUser cId (lIds <> [lId]) nt (Map.keys ngs)
graph <- liftIO $ cooc2graph 0 myCooc graph <- liftIO $ inMVarIO $ cooc2graph 0 myCooc
let graph' = set graph_metadata (Just metadata) graph let graph' = set graph_metadata (Just metadata) graph
pure graph' pure graph'
......
...@@ -25,7 +25,7 @@ import Data.Map (Map, fromListWith, lookup, fromList, delete, toList, mapKeys, m ...@@ -25,7 +25,7 @@ import Data.Map (Map, fromListWith, lookup, fromList, delete, toList, mapKeys, m
import qualified Data.Map as DM import qualified Data.Map as DM
import Data.Maybe (fromJust) import Data.Maybe (fromJust)
import Data.List (concat, sortOn) import Data.List (concat, sortOn)
import Data.Graph.Clustering.Louvain.CplusPlus (LouvainNode(..)) import Data.Graph.Clustering.Louvain.Utils (LouvainNode(..))
-- TODO mv in Louvain Lib -- TODO mv in Louvain Lib
......
...@@ -8,6 +8,9 @@ Portability : POSIX ...@@ -8,6 +8,9 @@ Portability : POSIX
Main IGraph funs/types to ease portability with FGL. Main IGraph funs/types to ease portability with FGL.
Reference:
* Gábor Csárdi, Tamás Nepusz: The igraph software package for complex network research. InterJournal Complex Systems, 1695, 2006.
-} -}
{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE NoImplicitPrelude #-}
......
...@@ -15,10 +15,8 @@ Portability : POSIX ...@@ -15,10 +15,8 @@ Portability : POSIX
module Gargantext.Viz.Graph.Tools module Gargantext.Viz.Graph.Tools
where where
import Control.Monad.IO.Class (liftIO)
import Control.Concurrent (newEmptyMVar, takeMVar, putMVar, forkIO)
import Debug.Trace (trace) import Debug.Trace (trace)
import Data.Graph.Clustering.Louvain.CplusPlus (LouvainNode(..)) import Data.Graph.Clustering.Louvain.Utils (LouvainNode(..))
import Data.Graph.Clustering.Louvain.CplusPlus (cLouvain) import Data.Graph.Clustering.Louvain.CplusPlus (cLouvain)
import Data.Map (Map) import Data.Map (Map)
import qualified Data.Set as Set import qualified Data.Set as Set
...@@ -70,20 +68,21 @@ cooc2graph threshold myCooc = do ...@@ -70,20 +68,21 @@ cooc2graph threshold myCooc = do
n' = Set.size $ Set.fromList $ as <> bs n' = Set.size $ Set.fromList $ as <> bs
ClustersParams rivers level = {-trace ("nodesApprox: " <> show nodesApprox) $-} clustersParams nodesApprox ClustersParams rivers level = {-trace ("nodesApprox: " <> show nodesApprox) $-} clustersParams nodesApprox
partitionsV <- liftIO newEmptyMVar partitions <- inMVarIO $ case Map.size distanceMap > 0 of
partitions' <- case Map.size distanceMap > 0 of
True -> trace ("level" <> show level) $ cLouvain level distanceMap True -> trace ("level" <> show level) $ cLouvain level distanceMap
False -> panic "Text.Flow: DistanceMap is empty" False -> panic "Text.Flow: DistanceMap is empty"
_ <- liftIO $ forkIO $ putMVar partitionsV partitions' bridgeness' <- trace "bridgeness" $ inMVar $ {-trace ("rivers: " <> show rivers) $-}
partitions <- liftIO $ takeMVar partitionsV
let bridgeness' = {-trace ("rivers: " <> show rivers) $-}
bridgeness rivers partitions distanceMap bridgeness rivers partitions distanceMap
let confluence' = confluence (Map.keys bridgeness') 3 True False confluence' <- trace "confluence" $ inMVar $ confluence (Map.keys bridgeness') 3 True False
r <- trace "data2graph" $ inMVarIO $ data2graph (Map.toList ti) myCooc' bridgeness' confluence' partitions
pure r
data2graph (Map.toList ti) myCooc' bridgeness' confluence' partitions
data ClustersParams = ClustersParams { bridgness :: Double data ClustersParams = ClustersParams { bridgness :: Double
......
...@@ -19,6 +19,7 @@ module Gargantext.Viz.Phylo.Cluster ...@@ -19,6 +19,7 @@ module Gargantext.Viz.Phylo.Cluster
where where
import Control.Parallel.Strategies import Control.Parallel.Strategies
import Data.Graph.Clustering.Louvain.CplusPlus import Data.Graph.Clustering.Louvain.CplusPlus
import Data.Graph.Clustering.Louvain.Utils (LouvainNode(..))
import Data.List (null,concat,sort,intersect,(++), elemIndex, groupBy, nub, union, (\\), (!!)) import Data.List (null,concat,sort,intersect,(++), elemIndex, groupBy, nub, union, (\\), (!!))
import Data.Map (Map, fromList, mapKeys) import Data.Map (Map, fromList, mapKeys)
import Data.Tuple (fst) import Data.Tuple (fst)
......
...@@ -4,6 +4,7 @@ extra-package-dbs: [] ...@@ -4,6 +4,7 @@ extra-package-dbs: []
packages: packages:
- . - .
#- 'deps/servant-job' #- 'deps/servant-job'
#- 'deps/clustering-louvain'
docker: docker:
enable: false enable: false
...@@ -49,7 +50,7 @@ extra-deps: ...@@ -49,7 +50,7 @@ extra-deps:
- git: https://github.com/np/servant-job.git - git: https://github.com/np/servant-job.git
commit: 4016c76398a56e1a352a45b3ee9d698dd0dd2597 commit: 4016c76398a56e1a352a45b3ee9d698dd0dd2597
- git: https://gitlab.iscpif.fr/gargantext/clustering-louvain.git - git: https://gitlab.iscpif.fr/gargantext/clustering-louvain.git
commit: e5814cbfa71f43b0a453efb65f476240d7d51a53 commit: f8fd33e4e9639730d47cd02b223a0f8fbbbfe975
- git: https://github.com/np/patches-map - git: https://github.com/np/patches-map
commit: 8c6f38c4844ead53e664cf9c82ba461715dbe445 commit: 8c6f38c4844ead53e664cf9c82ba461715dbe445
- git: https://github.com/delanoe/haskell-opaleye.git #- opaleye-0.6.7002.0 - git: https://github.com/delanoe/haskell-opaleye.git #- opaleye-0.6.7002.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment