Matrix transpose in OpenMP

Source: Internet
Author: User

// Hannuo. cpp: defines the entry point of the console application. // # Include "stdafx. H "# include" OMP. H "# include <windows. h> # include <iostream> # include <time. h> # define num_threads 2 using namespace STD; int _ tmain (INT argc, _ tchar * argv []) {omp_set_num_threads (num_threads); int A [400] [400]; // inint matrix int counter = 1; for (INT I = 0; I <400; I ++) {for (Int J = 0; j <400; j ++) {A [I] [J] = counter; counter ++; }}// for (INT I = 0; I <20; I ++) // {// For (Int J = 0; j <20; j ++) // cout <A [I] [J] <""; // Cout <Endl; //} cout <"parallel begin" <Endl; clock_t time_begin = clock (); int I = 0, j = 0; # pragma OMP parallel for private (I, j) for (I = 0; I <400; I ++) for (j = I + 1; j <400; j ++) // starts from I + 1. Run {long TMP = 0; TMP = A [I] [J]; A [I] [J] = A [J] [I]; A [J] [I] = TMP;} clock_t time_end = clock (); double S1 = time_end-time_begin; cout <"parallel end" <Endl; cout <"parallel time =" <S1 <Endl; // ================================================ ========================================================== ============================== time_begin = clock (); cout <"Serail begin" <Endl; For (INT I = 0; I <400; I ++) for (Int J = I + 1; j <400; j ++) // starts with I + 1. Run {int TMP = 0; TMP = A [I] [J]; A [I] [J] = A [J] [I]; A [J] [I] = TMP;} time_end = clock (); cout <"Serail end" <Endl; double S2 = time_end-time_begin; cout <"Serail time =" <S2 <Endl; System ("pause"); Return 0 ;}


Matrix transpose in OpenMP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.