PAPI 7.1.0.0
Loading...
Searching...
No Matches
prepareArray.c File Reference
Include dependency graph for prepareArray.c:

Go to the source code of this file.

Functions

static void _prepareArray_sections_random (uintptr_t *array, long long len, long long stride, long long secSize)
 
static void _prepareArray_sequential (uintptr_t *array, long long len, long long stride)
 
int prepareArray (uintptr_t *array, long long len, long long stride, long long secSize, int pattern)
 

Variables

volatile uintptr_t opt_killer_zero
 

Function Documentation

◆ _prepareArray_sections_random()

static void _prepareArray_sections_random ( uintptr_t *  array,
long long  len,
long long  stride,
long long  secSize 
)
static

Definition at line 41 of file prepareArray.c.

41 {
42
43 assert( array != NULL );
44
45 long long elemCnt, maxElemCnt, sec, i;
46 long long currElemCnt, uniqIndex, taken;
47 uintptr_t **p, *next;
48 long long currSecSize = secSize;
49 long long secCnt = 1+len/secSize;
50 long long *availableNumbers;
51
52 p = (uintptr_t **)&array[0];
53
54 maxElemCnt = currSecSize/stride;
55 availableNumbers = (long long *)calloc(maxElemCnt, sizeof(long long));
56
57 // Loop through every section in the array.
58 for(sec=0; sec<secCnt; ++sec){
59
60 // If we are at the last section, trim the size in order to link back to the first section.
61 if( sec == secCnt-1 )
62 currSecSize = (len%secSize);
63
64 for(i=0; i<maxElemCnt; i++)
65 availableNumbers[i] = i;
66
67 currElemCnt = currSecSize/stride;
68
69 taken = 0;
70
71 // For the first section, we have already picked "0", so we must pick one less element.
72 if( 0==sec )
73 taken = 1;
74 long long remainingElemCnt = currElemCnt;
75
76 for(elemCnt=0; elemCnt<currElemCnt-taken; ++elemCnt){
77 // Skip the first "taken" elements.
78 long long index = taken + random() % (remainingElemCnt-taken);
79 // For the first section, skip zero as a choice (we already selected it before the loop).
80 uniqIndex = sec*secSize + stride*availableNumbers[index];
81 // Replace the chosen number with the last element.
82 availableNumbers[index] = availableNumbers[remainingElemCnt-1];
83 // Shrink the effective array size so the last element "drops off."
84 remainingElemCnt--;
85
86 // Connect the link.
87 next = &array[uniqIndex];
88 *p = next;
89 p = (uintptr_t **)next;
90 }
91 }
92
93 // Close the circle by pointing the last element to the start.
94 next = &array[0];
95 *p = next;
96
97 free(availableNumbers);
98
99 return;
100}
int i
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
Here is the caller graph for this function:

◆ _prepareArray_sequential()

static void _prepareArray_sequential ( uintptr_t *  array,
long long  len,
long long  stride 
)
static

Definition at line 106 of file prepareArray.c.

106 {
107 long long curr;
108 uintptr_t **p, *next;
109
110 p = (uintptr_t **)&array[0];
111
112 // Point each element to the next in the array.
113 for(curr=0; curr<len; curr+=stride){
114 next = &array[curr];
115 *p = next;
116 p = (uintptr_t **)next;
117 }
118
119 // Close the circle by pointing the last element to the start.
120 next = &array[0];
121 *p = next;
122
123 return;
124}
Here is the caller graph for this function:

◆ prepareArray()

int prepareArray ( uintptr_t *  array,
long long  len,
long long  stride,
long long  secSize,
int  pattern 
)

Definition at line 18 of file prepareArray.c.

18 {
19 assert( array != NULL );
20 opt_killer_zero = (uintptr_t)( (len+37)/(len+36) - 1 );
21
22 switch(pattern){
23 case SECRND:
24 _prepareArray_sections_random(array, len, stride, secSize);
25 break;
26 case SEQUEN:
27 _prepareArray_sequential(array, len, stride);
28 break;
29 default:
30 fprintf(stderr,"prepareArray() unknown array access pattern: %d\n",pattern);
31 return -1;
32 break;
33 }
34 return 0;
35}
FILE * stderr
volatile uintptr_t opt_killer_zero
Definition: prepareArray.c:9
static void _prepareArray_sections_random(uintptr_t *array, long long len, long long stride, long long secSize)
Definition: prepareArray.c:41
static void _prepareArray_sequential(uintptr_t *array, long long len, long long stride)
Definition: prepareArray.c:106
#define SECRND
Definition: prepareArray.h:7
#define SEQUEN
Definition: prepareArray.h:8
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ opt_killer_zero

volatile uintptr_t opt_killer_zero

Definition at line 9 of file prepareArray.c.