Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Threading;
- namespace ConsoleApp1
- {
- class Program
- {
- public static double FirstThread(int Q, double N, double L, double t1, double t2, int m, int n, ref double[,] array)
- {
- for (int i = 1; i < n + 1; i+=2)
- {
- Thread.Sleep(100);
- L = 0;
- for (int j = 1; j < m + 1; j++)
- {
- array[i, j] = Math.Pow(Q * i / 100, 2);
- Console.Write("Thr1 = ");
- Console.Write(array[i, j]);
- Console.Write(" ");
- L += array[i, j];
- }
- Console.WriteLine();
- t1 += L;
- }
- return t1;
- }
- public static double SecondThread(int Q, double N, double L, double t1, double t2, int m, int n, ref double[,] array)
- {
- for (int i = 2; i < n + 1; i+=2)
- {
- Thread.Sleep(100);
- L = 0;
- for (int j = 1; j < m + 1; j++)
- {
- array[i, j] = Math.Pow(Q * i / 100, 2);
- Console.Write("Thr2 = ");
- Console.Write(array[i, j]);
- Console.Write(" ");
- L += array[i, j];
- }
- Console.WriteLine();
- t2 += L;
- }
- return t2;
- }
- static void Main(string[] args)
- {
- const int Q = 120;
- int n = Convert.ToInt32(Console.ReadLine());
- int m = Convert.ToInt32(Console.ReadLine());
- double L = 0, N = 0;
- double t1=0, t2=0;
- double[,] array = new double[n + 2, m + 1];
- var timer = Stopwatch.StartNew();
- Thread thr1 = new Thread(() => FirstThread(Q, N, L, t1, t2, m, n, ref array));
- Thread thr2 = new Thread(() => SecondThread(Q, N, L, t1, t2, m, n, ref array));
- thr1.Start();
- Thread.Sleep(10);
- thr2.Start();
- N = FirstThread(Q, N, L, t1, t2, m, n, ref array) + SecondThread(Q, N, L, t1, t2, m, n, ref array);
- Console.WriteLine(N);
- timer.Stop();
- Thread.Sleep(1000);
- Console.WriteLine("Выполнение метода заняло {0} мс", timer.ElapsedMilliseconds);
- Console.WriteLine("Выполнение метода заняло {0} тиков", timer.ElapsedTicks);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement