Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include "mpi.h"
- using namespace std;
- int main(int argc, char** argv)
- {
- int n, a, b;
- n = atoi(argv[1]);
- a = atoi(argv[2]);
- b = atoi(argv[3]);
- int size, rank;
- MPI_Status status;
- MPI_Init(&argc, &argv);
- MPI_Comm_size(MPI_COMM_WORLD, &size);
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- srand(rank);
- int blocksize = n / size;
- if (rank < n % size)
- ++blocksize;
- bool flag = true;
- bool proc_flag = true;
- int res = 0;
- int proc_res = 0;
- int arr[blocksize];
- for (int i = 0; i < block_size; ++i) {
- arr[i] = rand();
- if ((i > 0) && (arr[i - 1] > arr[i])) {
- proc_falg = false;
- }
- if (a <= arr[i] && arr[i] <= b) {
- ++proc_res;
- }
- }
- int bound;
- MPI_Request request1;
- MPI_Request request2;
- if (rank > 0) {
- MPI_Isend(arr[0], 1, MPI_INT, std::max(rank - 1, 0), 0, MPI_COMM_WORLD, &request1);
- MPI_Irecv(lb, 1, MPI_INT, std::max(rank - 1, 0), 0, MPI_COMM_WORLD, &request2);
- if (bound > arr[0]) {
- proc_flag = false;
- }
- }
- MPI_Reduce(&proc_res, &res, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
- MPI_Reduce(&proc_flag, &flag, 1, MPI_BOOL, MPI_LAND, 0, MPI_COMM_WORLD);
- MPI_Finalize();
- if (rank == 0) {
- if (flag) {
- cout << res;
- } else {
- return -1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement