-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set -N from the juvix global options
- Loading branch information
1 parent
f5ab7f8
commit 5e083b7
Showing
11 changed files
with
68 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Juvix.Data.NumThreads | ||
( NumThreads, | ||
defaultNumThreads, | ||
numThreadsOne, | ||
numThreads, | ||
mkNumThreads, | ||
mkNumThreads', | ||
) | ||
where | ||
|
||
import GHC.Conc | ||
import Juvix.Prelude.Base.Foundation | ||
import Prelude qualified | ||
|
||
-- | The number of jobs must be at least 1 | ||
newtype NumThreads = NumThreads Int | ||
deriving stock (Eq, Ord, Generic) | ||
|
||
instance Show NumThreads where | ||
show (NumThreads i) = show i | ||
|
||
numThreadsOne :: NumThreads | ||
numThreadsOne = NumThreads 1 | ||
|
||
numThreads :: NumThreads -> Int | ||
numThreads (NumThreads i) = i | ||
|
||
defaultNumThreads :: NumThreads | ||
defaultNumThreads = NumThreads (max 1 (numCapabilities - 2)) | ||
|
||
mkNumThreads :: Maybe Int -> Either String NumThreads | ||
mkNumThreads = \case | ||
Nothing -> Right defaultNumThreads | ||
Just n | ||
| n >= 1 -> return (NumThreads n) | ||
| otherwise -> Left "The number of jobs cannot be negative" | ||
|
||
mkNumThreads' :: Maybe Int -> NumThreads | ||
mkNumThreads' = either (error . pack) id . mkNumThreads |