- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to allocate 2D array, below is code for the same. It is compiling with some warning but is giving run time error. Please let me know the error in code and how to succefully allocate 2D array using Cilk.
#include <stdio.h>
#include <stdlib.h>
#include <cilk/cilk.h>
void _Cilk_shared Allocate_2D_float_Array(float _Cilk_shared **ptr, int n1, int n2);
int main(int argc, char* argv[])
{
float _Cilk_shared **a;
int n1, n2, i, j;
n1 = n2 = 2;
_Cilk_offload Allocate_2D_float_Array(a, n1, n2);
for(i=0; i<n1; i++)
{
for(j=0; j,n2; j++)
printf("%f \t",a
printf("\n");
}
return 0;
}
void _Cilk_shared Allocate_2D_float_Array(float _Cilk_shared **ptr, int n1, int n2)
{
int i, j;
ptr = (float _Cilk_shared**)_Offload_shared_malloc(n1*sizeof(float*));
for(i=0; i<n1; i++)
ptr = (float _Cilk_shared*)_Offload_shared_malloc(n2*sizeof(float));
for(i=0; i<n1; i++)
for(j=0; j,n2; j++)
ptr
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I thought this was a simple question until I tried it myself and found I couldn't get it to work. So I have passed the question on to those wiser than myself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The declarations for the _Cilk_shared aren't quite right, but even after correcting them there is a compiler bug in processing function parameters that causes a spurious diagnostic. As a temporary workaround, don't use a function parameter but hold the value in a global variable, as shown in the attached program.
It is also helpful to use typedefs for this kind of thing, for example:
typedef float* _Cilk_shared PSF;
typedef PSF * _Cilk_shared PPSF;
void _Cilk_shared Allocate_2D_float_Array(PPSF ptr, int n1, int n2);
There are also two bugs in the program that cause it to appear to hang even when the function parameter is converted to a global variable. Observe the two for-loops on "j":
for(j=0; j,n2; j++)
The j,n2 will cause an infinite loop. Correct that to j<n2;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I’d thought was a compiler bug in processing parameters was actually my own error in the typedefs. The typedefs to declare a “pointer to shared float” and “pointer to pointer to shared float” are as follows:
typedef _Cilk_shared float * PSF;
typedef _Cilk_shared PSF * PPSF;
With those typedefs the attached program compiles and runs correctly. A change had to be made to return the pointer to pointer to shared float from Allocate_2D_float_Array because otherwise it would be undefined on the CPU.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I’d thought was a compiler bug in processing parameters was actually my own error in the typedefs. The typedefs to declare a “pointer to shared float” and “pointer to pointer to shared float” are as follows:
typedef _Cilk_shared float * PSF;
typedef _Cilk_shared PSF * PPSF;
With those typedefs the attached program compiles and runs correctly. A change had to be made to return the pointer to pointer to shared float from Allocate_2D_float_Array because otherwise it would be undefined on the CPU.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page