none
OpenMP and /P RRS feed

  • 问题

  • Generally, we can use "/P" to output the code after pre-complying.

    For the source code that uses OpenMP programming directives, using "/P" does not make sense for the OpenMP directives, however, I want to do so and see how the OpenMP directives are used to transform parallel code to threads. 

    So, what should I do to fulfill the above goal?

    Thanks.

    2018年5月25日 0:26

全部回复

  • Hi,

    thanks for posting here.

    >>For the source code that uses OpenMP programming directives, using "/P" does not make sense for the OpenMP directives, however, I want to do so and see how the OpenMP directives are used to transform parallel code to threads. 

    Have you tried to obtain a listing of your source code after preprocessing by using the /E or /EP compiler option?  Both options invoke the preprocessor and output the resulting text to the standard output device, which, in most cases, is the console.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年5月25日 6:43
  • Hi,

    Thanks for the reply.

    I tried "/EP" option, however, it seems to be the same as "/P",the only difference is that the latter put the results into a file.

    The following the the code generated by the compiler with "/EP" option being set:

    >int main()
    1>{
    1> int iterationNum = 1000000;
    1> fstream outfile("result.txt", ios::app);
    1> double start, end;
    1> omp_set_num_threads(2);
    1> start = omp_get_wtime();
    1>#pragma omp parallel for
    1> for (int i = 0; i<iterationNum; i++)
    1> {
    1> if (omp_get_thread_num() == 0)
    1> printf("run threads number is %d\n",omp_get_num_threads());
    1> test();
    1> }
    1> end = omp_get_wtime();
    1> outfile << "with omp optimization, time elapsed is " << end - start << endl;
    1> outfile.close();
    1> return 0;
    1>}
    1>已完成生成项目“OpenMPexamples.vcxproj”的操作。
    ========== 生成: 成功 1 个,失败 0 个,最新 0 个,跳过 0 个 ==========

    2018年5月28日 12:51
  • >>I tried "/EP" option, however, it seems to be the same as "/P",the only difference is that the latter put the results into a file.
    The following the the code generated by the compiler with "/EP" option being set:

    It seems this compiler option doesn't work for OpenMP directives.

    Actually the parallel directive is used to define a parallel region. So that your code will be executed by multiple threads in parallel.

    For more information about OpenMP Directives, you could refer to this document below.

    https://msdn.microsoft.com/en-us/library/0ca2w8dk.aspx

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年5月29日 8:20