SPEC 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ------------------------------------------------------------------
  2. ECE 264 - SPRING 2013 - PROGRAMMING ASSIGNMENT 13
  3. ------------------------------------------------------------------
  4. In this assignment, you need to write README explaining how you
  5. solve the problem. You should write README and comments before
  6. writing code.
  7. INTRODUCTION
  8. ============
  9. PARALLEL PROGRAMMING
  10. ==========
  11. Due to Moore's Law, we are reaching the limits of being able to reduce
  12. the size of transistors in order to raise processor speeds. In order
  13. to continue to see improvement in computing performance, more and more
  14. systems are using multiple cores that can be programmed to run code in
  15. parallel. One way that is done are pthreads(POSIX thread). POSIX means Portable Operating System Interface; it is a standard for the programming interface of operating systems.
  16. ASSIGNMENT
  17. ==========
  18. Write a parallel C program that returns the answer for the following problem:
  19. Given a nonempty set S, with elements {a1, a2, a3, ...}, and a integer N,
  20. find the number of nonempty subsets of S, such that the sum of all elements
  21. in this subset equals to N.
  22. This problem is NP-complete, meaning that currently there is no way
  23. to sovle it efficiently. However, since this assignment is targeted for
  24. parallel computing, the algorithm is not an important part.
  25. You only need to take the simplest approach:
  26. enumerate all the subset of S, add up the elements and compare to N,
  27. count one if there is a match, and finally return the total number of counts.
  28. In this assignment, you need to submit the following files:
  29. README
  30. subsetSum.c
  31. You should write the function subsetSum() in subsetSum.c file and submit it.
  32. You may write your additional functions or structure inside subsetSum.c file.
  33. Please do not modify the other files.
  34. In this assignment, you should be aware of the Thread Synchronization.
  35. Please refer to the following explanation.
  36. Thread Synchronization:
  37. With multiple threads running in parallel updating a shared variable can
  38. potentially cause corruption of data. Therefore there needs to be some
  39. mechanism to guarantee that only one thread can update the shared variable
  40. at a time. Such process is termed as Thread Synchronization, referring to
  41. the fact that each thread needs to suspend its execution to form an
  42. agreement on how to access a shared resource, in order to gurantee integrity
  43. of the data. The code that accesses the shared resource that must not be
  44. access by two or more threads is called the critical section.
  45. In pthread the synchronization process is done by protecting the critical
  46. sections by using mutex objects. Mutex refers to mutual exclusion,
  47. which means no two threads can have controll over the object at the same time.
  48. A mutex object has two states, locked and unlocked. A thread first has to
  49. lock the mutext object in order to access the shared resource protected by
  50. the mutex. After it acquires the lock, it can step further to execute the
  51. critical section that access shared resources. A mutex object that is locked
  52. cannot be locked again, and only the thread acquired the lock can unlock it
  53. at any given time. If it is locked, other threads must wait for the owner
  54. of the lock to finish. When the thread finishes access to shared resources,
  55. it unlocks the mutex object and only by then can the other threads acquire
  56. the lock. This way ensures only one thread gets to access the common resource
  57. at any given time, therefore the threads are sychronized, and data integrity
  58. is guaranteed.
  59. SPECIFICATIONS
  60. ==============
  61. * You should use the following print statement if the dynamic memory
  62. is not allocated properly (and exit with EXIT_FAILURE):
  63. printf("Unable to allocate memory!\n");
  64. * The source files (argv[1], and argv[2]), the destination file (argv[3]),
  65. and the number of parallel thread you want to run (argv[4]) are
  66. command-line arguments.
  67. COMPILING AND EXECUTING
  68. =======================
  69. Warning messages are often indications of errors. For this assignment,
  70. you lose 0.1 point for each warning message. The command will generate
  71. an executable file called "pa13."
  72. To execute this program, type
  73. ./pa13 <input_set> <input_num> <output> <number of threads>
  74. You need to use you ece264 account to login into quatro01 or quatro02
  75. to run your program.
  76. A couple of the testcases are quite large. Running them may cause
  77. you to use all of the disk space. Be sure to check your space by typing
  78. 'quota'.
  79. MEMORY MANAGEMENT
  80. =================
  81. Memory management (allocation and release) is an important part of ECE
  82. 264. You have to allocate enough memory to make your program work. You
  83. have to allocate and release memory as needed. You are not allowed to
  84. allocate a large piece of memory regardless of the input size. We will
  85. restrict stack size to prevent that. You will receive a heavy penalty
  86. (50%) if your program does not release all memory (i.e. memory
  87. leak). We will use valgrind to check for memory leaks.
  88. GRADING
  89. =======
  90. The maximum score for this exercise is 4.0 points.
  91. We will first examine the correctness of your code. After checking
  92. correctness, we will then examine the runtimes of your code. If your
  93. code runs slower than the maximum allowed runtime, you will lose points
  94. in proportion with how much longer the runtime. Since multiple people
  95. may be running on the quatro machines, it is possible that the runtime
  96. of your program may be slower than it should be. If you feel that your program is faster than what is being reported, execute your program at
  97. another time.