回答
OpenMP運行時跟蹤線程局部變量中的這些信息。
可能是最流行的OpenMP實現之一,libgomp
,是開源的;這意味着不僅可以閱讀其文檔,而且可以閱讀完全免費的源代碼。
的omp_get_level()
實現是here:
int
omp_get_level (void)
{
return gomp_thread()->ts.level;
}
的gomp_thread()
實現是here。它檢索一個指向線程局部結構的指針。
#if defined __nvptx__
extern struct gomp_thread *nvptx_thrs __attribute__((shared));
static inline struct gomp_thread *gomp_thread (void)
{
int tid;
asm ("mov.u32 %0, %%tid.y;" : "=r" (tid));
return nvptx_thrs + tid;
}
#elif defined HAVE_TLS || defined USE_EMUTLS
extern __thread struct gomp_thread gomp_tls_data;
static inline struct gomp_thread *gomp_thread (void)
{
return &gomp_tls_data;
}
#else
extern pthread_key_t gomp_tls_key;
static inline struct gomp_thread *gomp_thread (void)
{
return pthread_getspecific (gomp_tls_key);
}
#endif
的數據結構ts
是struct gomp_team_state
的是,除其他外,contains:
[...]
/* Nesting level. */
unsigned level;
/* Active nesting level. Only active parallel regions are counted. */
unsigned active_level;
[...]
每當#pragma omp parallel
被使用時,編譯器提取並行部分的主體成一子功能併產生複雜一套函數調用最終導致gomp_team_start()
,其中contains:
#ifdef LIBGOMP_USE_PTHREADS
void
gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
unsigned flags, struct gomp_team *team)
{
[...]
++thr->ts.level;
if (nthreads > 1)
++thr->ts.active_level;
謝謝!所以這是openmp運行時庫如何跟蹤活動級別的嵌套。當然,用於openmp的預編譯器知道在構造導致gomp_teat_start()的複雜函數調用時嵌套了多少個循環。 總之,active_level在運行時計數。靜態地,openmp預編譯器對循環執行分析並且可以找到循環計數 – syko
這並沒有真正回答這個問題,因爲它涉及並行區域的嵌套而不是循環,除非問題被嚴重地提出。 –
@HristoIliev我對這個問題的解釋是,「嵌套級別」無法引用全局(callstack)或局部(單個函數內)的循環級別的C語言。 C語言不會全局跟蹤它。編譯器對函數中的本地嵌套級別具有普通訪問權限,但程序員也是如此。所以這必須是一個全局的OpenMP概念,OpenMP中唯一類似的概念是'omp_get {_active} _level()'的返回值。我指出它計數'#pragma omp parallel'的水平,但'parallel'經常(但並非總是)與'for'實例關聯。 –
- 1. OpenMP;嵌套循環
- 2. 多維嵌套的OpenMP循環
- 3. Openmp嵌套循環與有序輸出
- 4. OpenMP沒有表現:嵌套循環
- 5. 如何在while循環的嵌套for循環中使用OpenMP?
- 6. OpenMP嵌套循環索引依賴
- 7. OpenMP SIMD嵌套循環矢量化
- 8. OpenMP和嵌套與循環continue語句
- 9. OpenMP與STL容器嵌套For循環
- 10. OpenMP嵌套循環(使用Qt)
- 11. OpenMP和不平衡嵌套循環
- 12. 我如何知道Waypoint一次切換了多少個實例?
- 13. 如何通過遞歸實現未知層的嵌套循環?
- 14. 嵌套循環實現
- 15. 使用OpenMP在C和兩個嵌套循環中崩潰
- 16. 更多嵌套循環python
- 17. 如何爲嵌套循環配置openMP以保持內部循環不被並行化?
- 18. 如何使嵌套循環
- 19. 遞增多個嵌套雖然循環
- 20. 創建多個嵌套循環
- 21. MySQL的多個行,嵌套循環
- 22. 打破了多個嵌套而循環
- 23. 如何嵌套這個for循環?
- 24. 嵌套循環
- 25. openmp並行for循環與兩個或更多的減少
- 26. 在shell腳本中循環參數數組,不知道有多少個參數?
- 27. Python:兩個嵌套循環
- 28. Ruby嵌套每個循環
- 29. 我如何知道這個實例被釋放的位置?
- 30. 嵌套循環:當被執行時
'#pragma omp for collapse(n)',請參見[specification](http://www.openmp.org/wp-content/uploads/openmp-4.5.pdf)。 –