Difference between revisions of "Fork Loop Assignment"

From CSE231 Wiki
Jump to navigation Jump to search
Line 35: Line 35:
 
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(java.lang.Class,T%5B%5D,fj.api.TaskFunction) join_fork_loop(returnValueComponentType, array, task)] will perform exactly what we want, but we need to also pass the component type of the array return type.
 
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(java.lang.Class,T%5B%5D,fj.api.TaskFunction) join_fork_loop(returnValueComponentType, array, task)] will perform exactly what we want, but we need to also pass the component type of the array return type.
  
What is the component type of <code>Double[]</code>? {{Spoiler|<code>Double.class</code>}}
+
How do you specify the component type of <code>Double[]</code>? {{Spoiler|<code>Double.class</code>}}
  
 
===client===
 
===client===

Revision as of 02:57, 29 January 2023

Motivation

There are many incantations of the fork_loop. We gain experience with selecting the right one for two scenarios.

Background

Code To Use

FJ<E>

class FJ<E>

join_fork_loop(iterable, task)
join_fork_loop(returnValueComponentType, array, task)

Code To Implement

Echoes

class: Echoes.java Java.png
methods: toEchoes
package: forkloop.group
source folder: student/src/main/java

toEchoes

method: public static List<String> toEchoes(List<String> texts) Parallel.svg (parallel implementation required)

for each text in parallel, produce text + " " + text.

toEchoes accepts a List<String> parameter and returns a List<String>.

List<E> is an Iterable<E>, so instances of List<E> can be passed to join_fork_loop(iterable, task).

client

class: EchoClient.java DEMO: Java.png
methods: main
package: forkloop.client
source folder: src/main/java

SquareRoots

class: SquareRoots.java Java.png
methods: toSquareRoots
package: forkloop.group
source folder: student/src/main/java

toSquareRoots

method: public static Double[] toSquareRoots(Double[] values) Parallel.svg (parallel implementation required)

toSquareRoots accepts an array parameter and returns an array.

join_fork_loop(returnValueComponentType, array, task) will perform exactly what we want, but we need to also pass the component type of the array return type.

How do you specify the component type of Double[]?

client

class: SquareRootClient.java DEMO: Java.png
methods: main
package: forkloop.client
source folder: src/main/java

Testing

class: _ForkLoopTestSuite.java Junit.png
package: forkloop.group
source folder: testing/src/test/java