- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I wrote a simple application, attached at following, using offloads and streams and made a local copy from variable i for each stream with clause in. After the program was executed, I found that variable i is shared among all streams. Please let me know how we can create a local copy for a variable in offloads that other offloads cannot change its value.
..............................................................
#include"stdio.h"
#include"offload.h"
#include <mkl.h>
#include <miclib.h>
#include <unistd.h>
#define ALLOC alloc_if(1)
#define FREE free_if(1)
#define RETAIN free_if(0)
#define REUSE alloc_if(0)
const int SIZE=4;
int i,j,m,n,k;
main()
{
_Offload_stream handle[SIZE];
for(i=0; i< SIZE; i++)
handle = _Offload_stream_create(0, 1);
m=n=k= 3000;
double *a,*b,*c;
a = (double *)malloc(m*k*sizeof(double));
b = (double *)malloc(n*k*sizeof(double));
c = (double *)malloc(m*n*sizeof(double));
for(i = 0; i<m*n; i++)
a = b = c = i;
#pragma offload_transfer target (mic) in(a:length(m*k) ALLOC RETAIN)
#pragma offload_transfer target (mic) in(b:length(k*n) ALLOC RETAIN)
#pragma offload_transfer target (mic) in(c:length(m*n) ALLOC RETAIN)
#pragma offload_transfer target (mic) in(m,n,k: ALLOC RETAIN)
for(i=0;i<SIZE;i++)
{
//#pragma offload_transfer target (mic) in(i: ALLOC RETAIN) stream(handle)
#pragma offload target (mic) in(i: ALLOC FREE) nocopy(a,b,c, m,n,k: REUSE RETAIN) stream(handle)
{
fprintf(stderr, "start, i = %i\n", i);
char trans = 'N';
double alpha, beta;
alpha = beta = 1;
dgemm(&trans, &trans, &m, &n, &k, &alpha, a, &m, b, &m, &beta, c, &m);
fprintf(stderr, "stop, i = %i\n", i);
}
usleep( 1000 * 1000 );
}
i = 1000;
#pragma offload_wait target(mic) stream(0)
}
...............................................................................
output is:
start, i = 0
start, i = 1
start, i = 2
start, i = 3
stop, i = 3
stop, i = 3
stop, i = 3
stop, i = 3
..................................................................................
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found that variable i should be defined in main block. Could somebody explain why defining variable i globally resulted in the aforementioned problem?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is inherent in the design of the offload language extensions. File scope variable's (i.e. static data) values are always maintained and persist across offloads. Function scope variable's (i.e. stack data) values are not persistent across offloads.
The function scope variable is best suited for what you describe wanting.
Also, just FYI, alloc_if/free_if modifiers only apply to pointer data. The uses with variable ‘i’ are not applicable in your example.
Sorry for the delayed reply. We're experienced delays in visibility of some posts in our Forums due to measures our Forum Development team has taken to combat spam.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page