mapConcurrentlyChunked

parent 65281c78
...@@ -32,10 +32,13 @@ import qualified Data.IntMap as DM ...@@ -32,10 +32,13 @@ import qualified Data.IntMap as DM
import Data.Map (Map) import Data.Map (Map)
import Data.Text (Text) import Data.Text (Text)
import Data.List (cycle) import Data.List (cycle, concat)
import Data.List.Split (chunksOf)
import System.IO (hPutStr, hFlush, stderr) import System.IO (hPutStr, hFlush, stderr)
import System.Environment import System.Environment
import Control.Concurrent.Async as CCA (mapConcurrently) import Control.Concurrent.Async as CCA (mapConcurrently)
import Control.Concurrent (getNumCapabilities)
import Prelude ((>>))
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Core import Gargantext.Core
...@@ -58,18 +61,22 @@ mapMP f xs = do ...@@ -58,18 +61,22 @@ mapMP f xs = do
liftIO $ hFlush stderr liftIO $ hFlush stderr
f x f x
mapConcurrentlyChunked :: (a -> IO b) -> [a] -> IO [b]
mapConcurrentlyChunked f ts = do
n <- getNumCapabilities
concat <$> mapConcurrently (mapM f) (chunksOf n ts)
filterTermsAndCooc filterTermsAndCooc
:: TermType Lang :: TermType Lang
-> (Int, [Text]) -> (Int, [Text])
-> IO (Map (Terms, Terms) Coocs) -> IO (Map (Terms, Terms) Coocs)
filterTermsAndCooc patterns (year, ts) = do filterTermsAndCooc patterns (year, ts) = do
putStrLn $ "start filterTermsAndCooc " <> show year log "start"
r <- coocOn identity <$> mapM (terms patterns) ts r <- coocOn identity <$> mapM (\x -> {-log "work" >>-} terms patterns x) ts
putStrLn $ "stop filterTermsAndCooc " <> show year log "stop"
pure r pure r
where
log m = putStrLn $ "filterTermsAndCooc: " <> m <> " " <> show year
--main :: IO [()] --main :: IO [()]
main = do main = do
...@@ -92,6 +99,6 @@ main = do ...@@ -92,6 +99,6 @@ main = do
let corpus' = DMaybe.catMaybes $ map (\k -> DM.lookup k corpus) years let corpus' = DMaybe.catMaybes $ map (\k -> DM.lookup k corpus) years
r <- mapConcurrently (filterTermsAndCooc patterns) (zip years corpus') r <- mapConcurrentlyChunked (filterTermsAndCooc patterns) (zip years corpus')
putStrLn $ show r putStrLn $ show r
--writeFile outputFile cooc --writeFile outputFile cooc
...@@ -168,6 +168,7 @@ executables: ...@@ -168,6 +168,7 @@ executables:
- cassava - cassava
- ini - ini
- optparse-generic - optparse-generic
- split
- unordered-containers - unordered-containers
- full-text-search - full-text-search
......
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