Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 559053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:11:49+00:00 2026-05-13T12:11:49+00:00

I have a small numerical simulation in C (I had to do it in

  • 0

I have a small numerical simulation in C (I had to do it in C to share it with my advisor) but I want to use a “haskell script” like thing to organize the simulation. The program accepts some command line arguments and spits some output I’d like to redirect to a file, so I did something like this:

 import Control.Monad
 import System.Process

I have a function to create the name of the output file:

filename :: Int -> String  
filename n = some stuff here...

and the command I wanna run:

command :: Int -> String
command n = "./mycutesimulation " ++ show n ++ " >" ++ filename n

and finally I produce a list of the runs I wanna make and run them in with runCommand:

commands = map command [1,2..1000]

main = do
   sequence_ $ map runCommand commands

The problem is that after I run this “script”, my computer almost freezes with the load. The program that is being executed is very light in memory use and runs in a fraction of a second. This shouldn’t happen.

So, my questions are:

1) Did I just threw 1000 processes to be executed at the same time??? How can I execute them in a rational order – sequentially or just a few processes at a time.

2)I’m running this in a quad core and it’d be nice to use this in my favour. Is there a way I can compile this with that -threaded flag and get the processes to be concurrently executed but in an organized way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:11:49+00:00Added an answer on May 13, 2026 at 12:11 pm

    First of all you should check top or task manager to see if you are indeed creating 1000 processes in quick succession and then look for a solution based on that.

    An easy way to slow down process creation is to wait for each process to finish before creating the next one. So instead of mapping runCommand over your commands you should map your own function which first calls runCommand and then calls waitForProcess on the returned ProcessHandle, i.e. each invocation of your helper function will block until the spawned process had finished.

    The downside of the above solution is that it will only use one of your four cores. So what you could do to make use of all four cores is to partition commands into four (or as many cores as you want to use) lists, then spawn four worker threads with forkIO for each sublist that will each run the map on that sublist.

    Btw. mapM_ f == sequence_ . map f

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 340k
  • Answers 340k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In wp-includes/theme.php you’ll find the function switch_theme(). It offers an… May 14, 2026 at 4:45 am
  • Editorial Team
    Editorial Team added an answer A single table will be fine. If you have a… May 14, 2026 at 4:45 am
  • Editorial Team
    Editorial Team added an answer This has already been pointed out and i don't think… May 14, 2026 at 4:45 am

Related Questions

I have been asked to test a library provided by a 3rd party. The
I'm wanting to find the number of mantissa digits and the unit round-off on
I need to generate random numbers from Binomial(n, p) distribution. A Binomial(n, p) random
When designing tables, I've developed a habit of having one column that is unique
I have created a few small flash widgets that stream .mp3 audio from an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.