Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <mpi.h>
- using namespace std;
- double tBegin, tEnd;
- int main(int argc, char* argv[])
- {
- MPI_Init(&argc, &argv);
- unsigned int n;
- cout << "Wprowadz n" << endl;
- cin >> n;
- double* G = new double[n * n];
- double* C = new double[n * n];
- double* a = new double[n];
- double* u = new double[n];
- double* v = new double[n];
- double alfa, beta;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- G[i * n + j] = 0.4;
- C[i * n + j] = 0.7;
- }
- }
- for (int i = 0; i < n; i++)
- {
- a[i] = 0.2;
- u[i] = 0.3;
- v[i] = 0.4;
- }
- alfa = 0.6;
- beta = 0.7;
- tBegin = MPI_Wtime();
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < n * n; j++)
- {
- G[j] = beta * G[j] - C[j];
- }
- for (int j = 0; j < n; j++)
- {
- alfa = v[j] * u[j];
- }
- for (int j = 0; j < n; j++)
- {
- u[j] = alfa * v[j] - a[j];
- }
- for (int j = 0; j < n; j++)
- {
- for (int k = 0; k < n; k++)
- {
- v[j] = G[j * n + k] * u[k];
- }
- }
- beta -= v[i] * a[i];
- }
- tEnd = MPI_Wtime();
- cout << "Wartosci obliczone: " << endl;
- // cout << "G = " << endl;
- // for (int i = 0; i < n; i++)
- // {
- // for (int j = 0; j < n; j++)
- // cout << G[i * n + j] << " ";
- // cout << endl;
- // }
- // cout << "alfa=" << alfa << endl;
- // cout << "u = " << endl;
- // for (int i = 0; i < n; i++)
- // cout << u[i] << " ";
- // cout << endl;
- // cout << "v = " << endl;
- // for (int i = 0; i < n; i++)
- // cout << v[i] << " ";
- // cout << endl;
- cout << "beta min = " << beta << endl;
- cout << "Czas: " << tEnd - tBegin << endl;
- MPI_Finalize();
- return 0;
- }
Add Comment
Please, Sign In to add comment