1. Home
  2. Explore
  3. Computer Science
  4. Parallel Computing

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Parallel Computing

  • 50Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Parallelism Basics

In the work-sharing example, how long would 10 men take to finish a job that takes one man 10 days, assuming the work can be divided evenly?

50 questions

  1. 1

    In the work-sharing example, how long would 10 men take to finish a job that takes one man 10 days, assuming the work can be divided evenly?

    Model answer

    They would take 1 day because each man completes one-tenth of the work in parallel.

    Explanation

    Dividing a large job among workers allows multiple parts to be completed at the same time.

  2. 2

    What is parallelization in a computer system?

    Model answer

    Parallelization divides a large job into smaller tasks that separate computing entities execute at the same time.

    Explanation

    The smaller tasks collectively complete the original job more quickly.

  3. 3

    Why can parallelization improve an application's performance?

    Model answer

    It allows parts of a job to run simultaneously rather than requiring one computing entity to perform all the work sequentially.

    Explanation

    Doing work at the same time can reduce the total completion time.

  4. 4

    What role can a GPU play in parallel computing?

    Model answer

    A GPU can perform thousands of tasks in parallel, with each task contributing a small part of a larger job.

    Explanation

    The simultaneous execution of many small tasks can reduce the time needed for the larger job.

  5. 5

    What is a thread, and how is it related to a process?

    Model answer

    A thread is an execution entity, like a process, but it is a lightweight execution context that runs within a process.

    Explanation

    Threads support parallel execution while sharing many resources of their process.

  6. 6

    A program has a long sequential calculation and the computer has four processors. Why might the program use only one processor?

    Model answer

    If the program has only one execution path, the scheduler can run that process on one processor, leaving the others available for other work.

    Explanation

    Multiple processors do not automatically make a sequential program perform multiple parts of its work simultaneously.

  7. 7

    How is a program turned into a process in the described workflow?

    Model answer

    A compiler such as gcc creates an executable, and running that executable creates a process.

    Explanation

    The resulting process has its own memory space, some of which may reside in RAM.

  8. 8

    What does the original add all function do in the example program?

    Model answer

    It sequentially adds the first 10 million positive integers, returns the sum, and the main function prints it.

    Explanation

    The example uses an intentionally iterative calculation to illustrate how its work could be parallelized.

  9. 9

    How could the sum of 10 million numbers be divided across four workers?

    Model answer

    Divide the range into four quarters of 2.5 million numbers and assign one quarter to each worker.

    Explanation

    Each worker computes a partial sum, and the partial sums can then be combined.

  10. 10

    How many fork system calls are needed to create four separate processes for the four quarters of the calculation?

    Model answer

    Four fork system calls are needed, one to create each process.

    Explanation

    Each call creates a process to perform one quarter of the work.

  11. 11

    What does it mean that the four processes in the parallel sum example are isolated?

    Model answer

    Each process has its own instructions, data, heap, and stack, separate from those of the other processes.

    Explanation

    This separation means one process cannot simply use another process's memory as shared data.

  12. 12

    Why do separate processes need interprocess communication to exchange results or other information?

    Model answer

    Their memory spaces are isolated, so processes need IPC mechanisms to communicate with one another.

    Explanation

    The content describes message passing and shared memory as two IPC approaches.

  13. 13

    How can processes communicate using message passing?

    Model answer

    They can use send and receive system calls, with the operating system providing a communication channel.

    Explanation

    The operating system supports communication between otherwise isolated processes.

  14. 14

    How can shared memory be used for communication between processes?

    Model answer

    A shared memory region can be created using system calls and then used by processes to exchange information.

    Explanation

    The shared region provides a way for processes to access common data despite their otherwise separate memory spaces.

  15. 15

    Why can process-based parallelism involve substantial operating-system overhead?

    Model answer

    Process creation and management, IPC, and operations such as file handling involve system calls that transfer execution to the operating system.

    Explanation

    A system call triggers a software trap, after which the operating system identifies and handles the requested call.

  16. 16

    Besides system-call overhead, what inefficiency can arise when similar jobs run in separate processes?

    Model answer

    Processes may duplicate instructions and data, such as code and global data, even when those resources are similar across the processes.

    Explanation

    This duplication is one reason a thread-based approach can reduce the overhead of parallel work.

  17. 17

    How does a thread-based version of the four-part sum differ from using four processes?

    Model answer

    It creates one process and runs four threads within it, with each thread calculating one quarter of the sum.

    Explanation

    The threads can work in parallel while sharing resources belonging to their common process.

  18. 18

    Which process resources can threads in the same process share?

    Model answer

    They can share the process's code, global data, heap, and opened files.

    Explanation

    These shared resources distinguish threads in one process from separate, isolated processes.

  19. 19

    What memory region does each thread have for its own local variables and function calls?

    Model answer

    Each thread has its own stack.

    Explanation

    The stack also holds information needed for the thread's function calls.

  20. 20

    What information makes up a thread's execution context, and what is it used for?

    Model answer

    It includes the thread's stack and register values; these allow the thread to be stopped and restarted during a context switch.

    Explanation

    The content gives registers such as EIP and ESP as examples of execution-context state.

  21. 21

    Can threads in one process run on different processors or on the same processor?

    Model answer

    Yes. Threads may run on different processors, or they may be scheduled on the same processor at different times.

    Explanation

    The scheduler can assign thread execution contexts to available processors over time.

  22. 22

    How many threads can a process have at minimum, according to the described model?

    Model answer

    A process can execute with a single thread.

    Explanation

    A process with one execution context is described as having one thread.

  23. 23

    Can a thread execute independently without belonging to a process?

    Model answer

    No. A thread must be attached to a process in order to execute.

    Explanation

    A process can exist with a single thread, but a thread cannot exist as a standalone execution entity in this model.

  24. 24

    What happens to a process's threads when the process terminates?

    Model answer

    All threads belonging to that process terminate as well.

    Explanation

    Threads depend on their process for their execution environment.

  25. 25

    What happens to the rest of a process when one of its threads terminates?

    Model answer

    The other threads and the rest of the process can continue executing.

    Explanation

    A thread's termination does not by itself require the process or its remaining threads to terminate.

  26. 26

    What happens to a thread's stack when the thread dies?

    Model answer

    The thread's stack is reclaimed.

    Explanation

    Each thread owns its stack, so that stack is released when the thread terminates.

  27. 27

    Why are threads described as lightweight compared with processes?

    Model answer

    Threads share a process's resources and generally require less work to create, manage, and switch between than processes.

    Explanation

    Processes have separate memory spaces and more state to manage, while threads within one process share much of that state.

  28. 28

    What does the comparison of creating 50,000 processes and 50,000 threads illustrate?

    Model answer

    On the same machine, creating 50,000 threads can take much less time than creating 50,000 processes; one reported comparison was 0.9 versus 8.1 time units.

    Explanation

    The comparison illustrates that thread creation can be substantially more efficient than process creation.

  29. 29

    Why is communication between threads in one process usually easier than communication between separate processes?

    Model answer

    Threads can communicate through shared global data or the shared heap, whereas separate processes generally need IPC mechanisms.

    Explanation

    Message passing and creating or managing shared memory between processes involve system calls.

  30. 30

    Why can switching between threads in one process be faster than switching between processes?

    Model answer

    A thread switch generally requires saving less context, and it does not require changing the process's page tables.

    Explanation

    Threads share the process address space, so the same page tables remain active.

  31. 31

    How does keeping the same page tables during a thread switch affect the TLB?

    Model answer

    The TLB does not need to be flushed for a page-table change, and its cached entries can remain valid.

    Explanation

    Threads in one process use the same address space, preserving memory-translation locality.

  32. 32

    What happens to page tables and the TLB when switching between processes, as contrasted with switching threads?

    Model answer

    A process switch may require activating different page tables and updating the TLB, while a switch between threads of the same process does not change page tables.

    Explanation

    Changing address spaces adds overhead that is avoided when threads share a process.

  33. 33

    What is the purpose of the pthread_create function?

    Model answer

    It creates a new thread context in the process and starts that thread executing a specified function.

    Explanation

    The function accepts a thread identifier destination, attributes, a start routine, and an argument for that routine.

  34. 34

    What is the first argument to pthread_create used for?

    Model answer

    It points to a pthread_t variable that receives the new thread's identifier, or TID.

    Explanation

    The TID can later be used to identify the thread, including when waiting for it to finish.

  35. 35

    What is the role of the attributes argument in pthread_create?

    Model answer

    It specifies properties of the thread being created.

    Explanation

    In the example, the attributes argument is set to null.

  36. 36

    What does the start-routine argument to pthread_create specify?

    Model answer

    It is a pointer to the function where the new thread begins execution.

    Explanation

    The function runs in the new thread context.

  37. 37

    What does the final argument to pthread_create provide?

    Model answer

    It provides a pointer to the argument passed to the thread's start routine.

    Explanation

    The start routine receives this value when the new thread begins.

  38. 38

    What is the purpose of pthread_exit?

    Model answer

    It terminates the calling thread and can provide a pointer to the thread's return status.

    Explanation

    It serves a role for threads similar to the process exit operation.

  39. 39

    What does pthread_join do?

    Model answer

    It blocks the calling thread until a specified thread exits, then makes that thread's exit status available.

    Explanation

    The specified thread is identified by its TID.

  40. 40

    How is pthread_join similar to the process wait system call?

    Model answer

    Both allow one execution entity to wait for another to finish and obtain its exit status.

    Explanation

    pthread_join waits for a thread, while wait is used with processes.

  41. 41

    Does creating a thread with a pthread library call necessarily require a system call?

    Model answer

    Not necessarily; the library call used to create a thread may or may not require system calls.

    Explanation

    The described thread model contrasts this with creating four separate processes, which requires four fork calls.

  42. 42

    In the pthread sum example, why are four variables of type pthread_t defined?

    Model answer

    They store the identifiers of the four threads created for the four parts of the calculation.

    Explanation

    Each pthread_create call fills the corresponding variable with the new thread's TID.

  43. 43

    In the pthread sum example, why do all four threads use the same start routine?

    Model answer

    The shared routine performs the summing loop, while each thread's argument tells it which quarter of the range to process.

    Explanation

    One function can perform the same kind of work for different input ranges.

  44. 44

    How does a thread in the sum example determine which quarter of the numbers to add?

    Model answer

    It uses its argument as an identifier to calculate the start of its assigned range.

    Explanation

    The four thread identifiers select the four different 2.5-million-number portions.

  45. 45

    How is the sum of each thread's assigned range stored in the pthread example?

    Model answer

    Each thread writes its partial sum to its own element in a shared global array of four unsigned long values.

    Explanation

    The separate array elements hold the results for the four portions of the range.

  46. 46

    Why does the main thread call pthread_join for all four worker threads?

    Model answer

    It waits until every worker has finished calculating its partial sum before using the results.

    Explanation

    Each join blocks until its specified thread exits.

  47. 47

    How does the pthread sum example produce the final result?

    Model answer

    After joining the four worker threads, it adds the four partial sums and prints the total.

    Explanation

    The partial sums together represent the sum across the full range.

  48. 48

    What must be linked when compiling a program that uses the pthread library with gcc?

    Model answer

    The pthread library must be linked, as indicated by the -lpthread option.

    Explanation

    The described command compiles the source file and links the pthread library into the executable.

  49. 49

    What comparisons could be used to investigate the speedup from the pthread sum program?

    Model answer

    Compare its runtime with a sequential version and with a version that uses separate processes, varying the number of threads as appropriate.

    Explanation

    These comparisons show how execution time changes with different approaches to parallelizing the calculation.

  50. 50

    Name three thread libraries or library families mentioned besides the pthread library.

    Model answer

    Examples include the Windows threads library, Boost for C++, and Linux threads.

    Explanation

    The content notes that multiple libraries are available for creating multithreaded programs.

1 of 50
Question 1 of 50

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent