# Assignment 4 Solution

\$35.00 \$30.80

Category:

## Description

In this assignment you will sort trajectories of Whales based on the lengths of the trajectories, using GPU.

The Whale trajectories will be provided using a text file. The format of the file is following. The file line will have two numbers N and M. N represents the number of trajectories, and M represents the number of stops each trajectory has. For simplicity, you can consider all Whales will take the same number of stops.

Then, there will be N lines in the file, each line will contain M Cartesian coordinates (M pair of numbers in each line) where each pair indicates a stop. All Whale starts from the location (0,0).

When completed, you GPU based program will read two file names from command line argument list. The first file will be the whale trajectory file. The program, then read the trajectory file, upload the data to GPU, and perform calculation as follows. For each data, your GPU will calculate the length of the data. The length will be calculated by summing the Euclidian distances between consecutive stops, starting from (0,0). Then the GPU will sort the trajectory based on the length of the trajectories. Once the sort complete, the host program will download the sorted the data from GPU, and save it to file, as name given in the second argument.

You need to develop the program using computing programming model either CUDA or OpenCL.

Sample input file (input.dat)

4 2

051010

2246

102034

104 410
Sample output file (output.dat)

2246

051010

104 410

102034
Explanation

0 5 10 10 (distance 16.18)

2 2 4 6 (distance 7.30)

10 20 3 4 (distance 39.83)

10 4 4 10 (distance 19.26)

Individual Distance Calculation:

051010

(0,0) -> (0,5) => 5

(0,5) -> (10,10) => 11.18034

Total Trajectory (5+11.18034) = 16.18
Page 2 of 2