I verified both the sequential and the parallel codes. In both cases I have verified for up to N=5 (N=size of array = number of procs). I have checked termination, the resulting array is sorted and is a permutation of the original. First, the simple sequential algorithm: /* Challenge 3: part 1: the simple sequential algorithm * is verified. */ #include typedef double T; $input int N = 4; // upper bound on n $input int n; // size of array $assume(1<=n && n<=N); $input T A[n]; // input: constant, fixed forever /* Counts the number of occurences of val in the array * starting at p consisting of n ints */ int count(int n, T *p, T val) { int result = 0; for (int i=0; i list[i+1]) { swap(list, i, i+1); sorted = false; } } for (int i = 0; i < n-1; i += 2) { if (list[i] > list[i+1]) { swap(list, i, i+1); sorted = false; } } } } int main() { T a[n]; for (int i=0; i #include #include #include // change to whatever type you like. The MPI datatype and the C type must match... #define T double #define MPI_T MPI_DOUBLE $input int N = 4; // size of array: can be specified on command line with -inputN=... $input T A[N]; // input array : constant, fixed forever T myvalue; // this is a local variable for each process in MPI /* Counts the number of occurrences of val in the array * starting at p consisting of n elements of T. */ int count(int n, T *p, T val) { int result = 0; for (int i=0; i0) { MPI_Send(&myvalue, 1, MPI_T, id-1, 0, MPI_COMM_WORLD); MPI_Recv(&othervalue, 1, MPI_T, id-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); if (othervalue > myvalue) myvalue = othervalue; } } } } int main() { int nprocs, rank; MPI_Init(NULL, NULL); // initialize MPI MPI_Comm_size(MPI_COMM_WORLD, &nprocs); // get the number of procs MPI_Comm_rank(MPI_COMM_WORLD, &rank); // get my "rank" (id) $assert(nprocs == N); // number of procs must equal N myvalue = A[rank]; // get my value from the global input array A //printf("Before: rank=%d, myvalue=%f\n", rank, myvalue); oddEvenPar(nprocs, rank); // call the function that does the work //printf("After: rank=%d, myvalue=%f\n", rank, myvalue); if (rank == 0) { // proc 0 will gather all data and check it is correct T a[N]; // used for verification---gather all elements into one array on proc 0 MPI_Gather(&myvalue, 1, MPI_T, a, 1, MPI_T, 0, MPI_COMM_WORLD); $assert($forall (int i : 0..N-2) a[i]<=a[i+1]); $assert($forall (int i : 0..N-1) ($exists (int j : 0..N-1) a[i]==A[j])); $assert($forall (int i : 0..N-1) ($exists (int j : 0..N-1) A[i]==a[j])); for (int i=0; i