You are here:   ArielOrtiz.com > Programming Languages > Using Parallel Map

Using Parallel Map

Objectives

During this activity, students should be able to:

This activity helps the student develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.

Activity Description

Individually or in pairs, solve the following problem. This problem is an adaptation of problem 10 Summation of primes from Project Euler.

The sum of the primes below 10 is:

2 + 3 + 5 + 7 = 17

Find the sum of all the primes below five million.

Spoiler alert: The correct answer is 838,596,693,108.

Write a Clojure function that allows you to compute this solution in parallel (with the help of Clojure’s pmap function), using a computer system with a dual-core CPU or better. The name of the function must be prime-sum and it must be contained in a namespace called parallel (thus, your source file should be called parallel.clj). The function should take as an argument the number of threads to use during the computation.

For examples, theses expressions:

(time (println (parallel/prime-sum 1)))
(time (println (parallel/prime-sum 2)))
(time (println (parallel/prime-sum 4)))
(time (println (parallel/prime-sum 8)))

would produce (in a system with eight logical cores) the following output at the console:

parallel.clj: 838596693108
parallel.clj: "Elapsed time: 16667.419293 msecs"
parallel.clj: 838596693108
parallel.clj: "Elapsed time: 10960.127025 msecs"
parallel.clj: 838596693108
parallel.clj: "Elapsed time: 6997.414449 msecs"
parallel.clj: 838596693108
parallel.clj: "Elapsed time: 5770.025455 msecs"

NOTE: Elapsed times in your system may vary considerably from the ones presented here.

Please consider the following when programming your solution:

Deliverables

✔ Upload Instructions

Deliver a single file called parallel.clj containing your solution. Please provide the following information:

Request PIN

IMPORTANT: The program source file must include at the top the author's personal information (name and student id) within comments. For example:

;;; ITESM CEM, November 11, 2015.
;;; Clojure Source File
;;; Activity: Using Parallel Map
;;; Authors: 
;;;          A01166611 Pepper Pots
;;;          A01160611 Anthony Stark

    .
    . (The rest of the program goes here)
    .

Due date is Wednesday, November 11.

Evaluation

This activity will be evaluated using the following criteria:

-10 The program doesn't contain within comments the author's personal information.
10 The program contains syntax errors.
DA The program was plagiarized.
10-100 Depending on the quality of the solution.