Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Shanci_G_
Beginner
47 Views

Apply _CIlk_shared to static and local variables

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:

  1. static document shared pointer, compiler warning as "_Cilk_shared may not be applied to static variables", but the test has been passed;
  2. static document non-shared pointer to shared VM, no compiler warning and test passed;
  3. local non-shared pointer to shared VM, no compiler warning and test passed;
  4. local shared pointer, compiler warning as "_Cilk_shared may not be applied to local variables", but the test has been passed;
  5. 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

0 Kudos
0 Replies
Reply