3

I am trying to write a program with Shelly to compile Delphi projects in parallel. I thought the program would be blocked while waiting for the Delphi compilers to return. But my program starts to max out one CPU-core after compiled 2 projects. I couldn't work out what it's so busy doing. Please help? Thanks.

ps: I am quite new to Haskell, if I'm not implementing this the right way, pointers are appreciated.

{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Shelly 
import Shelly.Background

import Control.Monad
import Control.Arrow
import System.IO.Temp (withSystemTempDirectory)
import System.Directory (getCurrentDirectory)
import System.FilePath (splitFileName)
import Data.Text.Lazy (Text, pack)
default (Int, Text)

dcc32 = command "dcc32" ["-RC:\\Program Files\\Borland\\BDS\\4.0\\Lib", "-Q", "-H", "-W", "-B"]

compile project = liftIO $ withSystemTempDirectory "TempDCU_" compile'
  where
    compile' tmpDir = shellyNoDir $ silently $ 
      chdir dir (dcc32 [toTextIgnore file, pack $ "-N" ++ tmpDir])
    (dir, file) = mapTuple (fromText . pack) $ splitFileName project
    mapTuple = join (***)

compilePooled n projects = shellyNoDir $ jobs n (\job -> mapM (background job . compile) projects)

projectList = [
    "C:\\Path\\to\\project1.dpr",
    "C:\\Path\\to\\project2.dpr",
    "C:\\Path\\to\\project3.dpr",
    "C:\\Path\\to\\project4.dpr",
    ]

main = do
  output <- compilePooled 2 projectList
  shellyNoDir $ mapM getBgResult output >>= mapM_ inspect 
ePak
  • 484
  • 5
  • 12
  • 1
    Is the program compiled with the `-threaded` option? – MathematicalOrchid Oct 02 '12 at 08:39
  • No. Is that the problem? Couldn't test it until I get back to work tomorrow. But even then, I would thought there won't be do much stuff for it to do anyway? – ePak Oct 02 '12 at 09:10
  • It's possible that's the problem, but I wouldn't put money on it. It's an easy thing to try though... – MathematicalOrchid Oct 02 '12 at 09:21
  • Compiling with --threaded doesn't help. In fact, if running it with "+RTS -N3", it's using more than 25% CPU (quad-core). – ePak Oct 03 '12 at 01:43
  • If it is using more than 25% isn't it working in parallel then? Also it seems you are starting background processes, do you see them in your task manager? Also `jobs` doesn't promise to give you `n` background processes, but to not to execute more than `n` background processes. – Alessandro Vermeulen Feb 28 '13 at 21:05

0 Answers0