You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

  1. module Main where
  2. import System.Environment
  3. import ThreadPoolTimed
  4. import ThreadPoolTimed2
  5. initialVector :: [Int]
  6. initialVector = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
  7. main :: IO ()
  8. main = do args <- getArgs
  9. let sec = read (args !! 0) :: Int
  10. let rep = read (args !! 1) :: Int
  11. let cores = read (args !! 2) :: Int
  12. let evalf = (applyNtimes rep applyFun)
  13. putStrLn "\n\n"
  14. res2 <- threadPoolTimed cores sec evalf initialVector
  15. putStrLn $ "ThreadPool result: " ++ (show $ sum res2) ++ " \n"
  16. res1 <- threadPoolTimed2 sec evalf initialVector
  17. putStrLn $ "ThreadPool2 result: " ++ (show $ sum res1) ++ " \n"
  18. --res3 <- parallelizedTimed2 sec evalf initialVector
  19. --putStrLn $ "ParMap result: " ++ (show $ sum res3) ++ " \n"
  20. applyNtimes :: Int -> (a -> a) -> a -> a
  21. applyNtimes 0 _ accum = accum
  22. applyNtimes n f accum = applyNtimes (n - 1) f (f accum)
  23. applyFun :: Int -> Int
  24. applyFun x = x + 1