- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone:
I learn from the official document that _Cilk_shared cannot be applied to static variables and variables local to a function.
I've done some experiments with a demo. Here is my code:
#pragma offload_attribute (push, _Cilk_shared)
#include <offload.h>
#pragma offload_attribute (pop)
#include <stdio.h>
struct mic_int {
int p;
};
_Cilk_shared int test_result(_Cilk_shared struct mic_int * v) {
int result = v->p + 3;
return result;
}
// static _Cilk_shared struct mic_int * _Cilk_shared v;
// static _Cilk_shared struct mic_int * v;
int main() {
// _Cilk_shared struct mic_int * v;
// _Cilk_shared struct mic_int * _Cilk_shared v;
// static _Cilk_shared struct mic_int * _Cilk_shared v;
int result = 0; // Use placement new to construct an object in the shared memory space.
v = (_Cilk_shared struct mic_int*)_Offload_shared_malloc(sizeof(struct mic_int));
v->p = 6;
result = _Cilk_offload test_result(v);
//int threads_number = __cilkrts_get_nworkers();
//printf("the threads number is %d\n", threads_number);
if (result != 9)
printf("Failed\n");
else
printf("Passed\n");
_Offload_shared_free(v);
return 0;
}
The test results:
- static document shared pointer, compiler warning as "_Cilk_shared may not be applied to static variables", but the test has been passed;
- static document non-shared pointer to shared VM, no compiler warning and test passed;
- local non-shared pointer to shared VM, no compiler warning and test passed;
- local shared pointer, compiler warning as "_Cilk_shared may not be applied to local variables", but the test has been passed;
- local static shared pointer, compiler warning as "_Cilk_shared may not be applied to local variables", and the test failed, there is a segment fault!
Is there explanation about the official document and my demo results? The map of shared VM is a little confusing for me.
Thanks
yzgsc123
Link Copied
0 Replies
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page