OpenMP learning diary (a)

Since the election there is a special arrangement of the course work, they learn under openMP. Some doubts and all kinds of access to information obtained through its own before were consolidated, for their friends and interested SEE!

What is OpenMP?
At first, the teacher assigned to write a HelloWorld with OpenMP entry-level program, I thought it was next to a new software platform or compile, you can be scared me.
In fact, OpenMP is an abbreviation for Open MultiProcessing. OpenMP is not a simple library, but a lot of compiler support framework agreement or is it, in short, does not require any configuration , you can use it in Visual Studio or gcc in.

How to configure?
If your computer is equipped with VS, you need only the right project -> Properties -> C / C + ±> language specifically shown Here Insert Picture Description
that we start the Hello World program it
is first sent to the code

#include <iostream>
#include<omp.h>  //这就是OpemMP的头文件 只要按上述配置好就行
using namespace std;
int main()
{
    int tid;//定义线程号
    omp_set_num_threads(4);//设置四个线程
    /*并行区域开始*/
    #progma omp parallel private(tid)
    {
         tid=omp_get_thread_num;
         cout<<"This is No.  “<<tid<<"thread"<<endl;
         cout<<"Hello World"<<endl;
    }
    return 0;
}

Here, in my first try, there has been "C ++ / CLI, C ++ / CX or OpenMP does not support two-phase name lookup" in error, then we need only project -> Properties -> C / C + ±> Language -> in line mode: No can solve the problem.

Now let's look at the results: operation result
it seems as if our regular and imagination not the same form.
We might think it should be
This IS the Thread Add to Cart No.0
the Hello World!
IS No. 1 the Thread the this
the Hello World! ..
here is the difference between parallel and serial computing calculations of
my understanding is that we think the output forms can in fact be understood as a For loop, but still in order when one actually handles to deal with. Computing in parallel, which means, a plurality of processors simultaneously processed. Before a person to run 400m, it is now four people were run 100m. So there will be no so-called order, who are likely to be in front of, before there could be the go-ahead in behind the front.

Basic knowledge about OpenMP, will continue to expand in the subsequent free time, I would also like to learn more than relevant content, after all, I was the first contact, do not understand.

Well, first post on this end, although nothing seemed dry, but still out of a whole Hello world!

Published an original article · won praise 0 · Views 59

Guess you like

Origin blog.csdn.net/weixin_43827628/article/details/104592242