0

If I run some jobs in parallel like this:

#!/bin/bash
for i in `seq 1 100`; 
do
    ./program data$i.txt &  
done

this means that I need 100 cores? Or in case I don't have 100 cores some of the jobs will wait, or they will all be run on that lower number of cores, so more than 1 job will be allocated to a core? And in case I need 100 cores, what should I do to run 10 at a time, without having to make the for loop from 1 to 10 and run the bash file 10 times?

Silviu
  • 749
  • 3
  • 7
  • 17

1 Answers1

1

The operating system is responsible for process and thread scheduling.

Or in case I don't have 100 cores some of the jobs will wait

Yes, the jobs will wait. But it probably won't be apparent to you. One job won't wait for another job to finish before it begins. As each job is running, the operating system's scheduling algorithm may interrupt the process executing the job and yield the CPU to another process. See: Scheduling

excerpt :

Process scheduler

The process scheduler is a part of the operating system that decides which process runs at a certain point in time. It usually has the ability to pause a running process, move it to the back of the running queue and start a new process; such a scheduler is known as preemptive scheduler, otherwise it is a cooperative scheduler.

Amir Afghani
  • 37,814
  • 16
  • 84
  • 124