Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vector<T>& mulVector(const Vector<T>& vector) const {
- T* tmp = this->array;
- T* vec, res;
- char* argv[1]; argv[0] = nullptr;
- int argc = 0;
- MPI_Init(&argc, &argv);
- unsigned amount, rank;
- MPI_Comm_size(MPI_COMM_WORLD, &amount);
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- unsigned lines = size / amount;
- if (rank == 0) {
- T* vec = tmp;
- for (unsigned it = 1; it != amount; ++it)
- MPI_Send(tmp + it * lines * size, lines * size, MPI_DOUBLE, it, 1, MPI_COMM_WORLD);
- }
- else {
- T* vec = tmp + rank * lines * size;
- MPI_Recv(vec, lines * size, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
- }
- for (unsigned it = 0; it != lines; ++it)
- for (unsigned j = 0; j != size; ++j)
- res[it] += vec[it * size + j] * vector[j];
- if (rank != 0) {
- MPI_Send(res, lines, MPI_DOUBLE, 0, 2, MPI_COMM_WORLD);
- }
- else {
- T* final = T[size * size];
- for (unsigned it = 1; it != amount; ++it)
- MPI_Recv(final + it * lines * size, lines * size, MPI_DOUBLE, it, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
- Vector<T>& New = *(new Vector<T>(final, size));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement