forked from vijaygarg1/EE-360P
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50245f8
commit 3a61e97
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//UT-EID= | ||
|
||
|
||
import java.util.*; | ||
import java.util.concurrent.*; | ||
|
||
|
||
public class PMerge{ | ||
public static void parallelMerge(int[] A, int[] B, int[]C, int numThreads){ | ||
// TODO: Implement your parallel merge function | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//UT-EID= | ||
|
||
|
||
import java.util.*; | ||
import java.util.concurrent.*; | ||
|
||
public class PSort{ | ||
public static void parallelSort(int[] A, int begin, int end){ | ||
// TODO: Implement your parallel sort function | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import java.util.Arrays; | ||
|
||
public class SortTest { | ||
public static void main (String[] args) { | ||
int[] A1 = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; | ||
verifyParallelSort(A1); | ||
|
||
int[] A2 = {1, 3, 5, 7, 9}; | ||
verifyParallelSort(A2); | ||
|
||
int[] A3 = {13, 59, 24, 18, 33, 20, 11, 11, 13, 50, 10999, 97}; | ||
verifyParallelSort(A3); | ||
} | ||
|
||
static void verifyParallelSort(int[] A) { | ||
int[] B = new int[A.length]; | ||
System.arraycopy(A, 0, B, 0, A.length); | ||
|
||
System.out.println("Verify Parallel Sort for array: "); | ||
printArray(A); | ||
|
||
Arrays.sort(A); | ||
PSort.parallelSort(B, 0, B.length); | ||
|
||
boolean isSuccess = true; | ||
for (int i = 0; i < A.length; i++) { | ||
if (A[i] != B[i]) { | ||
System.out.println("Your parallel sorting algorithm is not correct"); | ||
System.out.println("Expect:"); | ||
printArray(A); | ||
System.out.println("Your results:"); | ||
printArray(B); | ||
isSuccess = false; | ||
break; | ||
} | ||
} | ||
|
||
if (isSuccess) { | ||
System.out.println("Great, your sorting algorithm works for this test case"); | ||
} | ||
System.out.println("========================================================="); | ||
} | ||
|
||
public static void printArray(int[] A) { | ||
for (int i = 0; i < A.length; i++) { | ||
if (i != A.length - 1) { | ||
System.out.print(A[i] + " "); | ||
} else { | ||
System.out.print(A[i]); | ||
} | ||
} | ||
System.out.println(); | ||
} | ||
} |