V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
woshichuanqilz
V2EX  ›  C++

使用 openmp 数组数据乱码

  •  
  •   woshichuanqilz · Mar 9, 2021 · 1634 views
    This topic created in 1875 days ago, the information mentioned may be changed or developed.

    代码在这里 https://github.com/woshichuanqilz/openmptest

    不使用 openmp 的话代码运行 ok 。

    我在代码里面加了 #pragma omp parallel for for(n=0;n<N_iter;n++) { Pointwg *xpoint=NULL; Pointwg *ypoint=NULL;

    出问题的行数是 519

    img[ypoint[m].wg]+=q1*ypoint[m].jx;

    运行一小段时间后出问题

    这一段 xpoint 后面是一个动态数组的指针, 后面取 xpoint 的值的时候会出现非常大的数据应该是乱码, 但是我不明白我这个变量是声明在 for 里面的那么只是应该受一个线程的控制, 那么为什么会出现数据错乱的问题, 还有就是这种问题如何有效的 debug?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   998 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:10 · PVG 03:10 · LAX 12:10 · JFK 15:10
    ♥ Do have faith in what you're doing.