17
# include <sys/types.h>
20
# include <sys/stat.h>
28
#include "../ra_common.h"
32
static int me, nproc,nsmp;
33
static u64Int procnumupdates,myglobalstart,globaltablelen,mytablelen,mintablesize,*procglobalstart;
34
static int bigtables,Remainder;
35
static int *armcismpid;
36
static int my_free_handle;
45
struct vector_dscr_t *next;
48
struct vector_dscr_t *vec_dscr;
49
static struct vector_dscr_t curdscr_val;
50
struct vector_dscr_t *curdscr_ptr = &curdscr_val;
52
static armci_hdl_t* _get_next_handle()
55
my_free_handle %= MAX_OUTSTANDING_HANDLES;
57
/* from hpcc RandomAccess/utility.c */
58
static u64Int HPCC_starts(s64Int n)
61
u64Int temp,ran,m2[64];
63
while (n < 0) n += PERIOD;
64
while (n > PERIOD) n -= PERIOD;
65
if (n == 0) return 0x1;
68
for (i=0; i<64; i++) {
70
temp = (temp << 1) ^ ((s64Int) temp < 0 ? POLY : 0);
71
temp = (temp << 1) ^ ((s64Int) temp < 0 ? POLY : 0);
87
ran = (ran << 1) ^ ((s64Int) ran < 0 ? POLY : 0);
93
static void xmitsmpvector(){
94
struct vector_dscr_t *tmp=curdscr_val.next, *tmp1;
95
int mysmpid = armcismpid[me];
97
curdscr_ptr = &curdscr_val;
99
printf("\n%d:in xmitsmpvector dstproc=%d dstsmp=%d mysmp=%d\n",me,tmp->dstproc,tmp->dstsmp,mysmpid);fflush(stdout);
102
if(tmp->dstsmp!=mysmpid)
103
ARMCI_NbAccV(ARMCI_ACC_RA,&myscale,&tmp->a_v,1,tmp->dstproc,NULL);
106
tmp=curdscr_val.next;
108
printf("\n%d:in xmitsmpvector1 dstproc=%d\n",me,tmp->dstproc);fflush(stdout);
111
if(tmp->dstsmp==mysmpid)
112
ARMCI_AccV(ARMCI_ACC_RA,&myscale,&tmp->a_v,1,tmp->dstproc);
115
tmp=curdscr_val.next;
117
printf("\n%d:in xmitsmpvector2 dstproc=%d\n",me,tmp->dstproc);fflush(stdout);
121
tmp->a_v.ptr_array_len=0;
127
printf("\n%d:in xmitsmpvector done\n",me);fflush(stdout);
132
static void addtosmpvector(u64Int ran){
135
struct vector_dscr_t *tmp;
136
offset = ran & (globaltablelen-1);
137
if(offset < bigtables)
138
proc=offset/(mintablesize+1);
140
proc=(offset-Remainder)/mintablesize;
142
smpid = armcismpid[proc];
144
printf("\n%d:adding ran=%d offset=%d proc=%d smpid=%d\n",me,ran,offset,proc,smpid);fflush(stdout);
146
tmp =&vec_dscr[smpid];
150
curdscr_ptr->next = tmp;
153
*(u64Int *)tmp->a_v.src_ptr_array[tmp->a_v.ptr_array_len]=ran;
154
tmp->a_v.dst_ptr_array[tmp->a_v.ptr_array_len]=(void *)(HPCC_Table[proc]+(offset-procglobalstart[proc]));
155
tmp->a_v.ptr_array_len+=1;
157
printf("\n%d:added ran=%d smpid=%d ptrarrlen=%d\n",me,ran,smpid,tmp->a_v.ptr_array_len);fflush(stdout);
161
void HPCCRandom_Access()
165
ran = HPCC_starts (4 * myglobalstart);
166
for(i=0;i<procnumupdates;i++){
167
ran = (ran << 1) ^ ((s64Int)ran < ZERO64B ? POLY : ZERO64B);
169
if(i && i%MAX_TOTAL_PENDING_UPDATES==0)xmitsmpvector();
171
if(i%MAX_TOTAL_PENDING_UPDATES)xmitsmpvector();
174
static void initialize_tables()
178
curdscr_val.next=NULL;
179
curdscr_ptr = &curdscr_val;
180
nsmp = armci_domain_count(d);
181
armcismpid = (int *)malloc(sizeof(int)*nproc);
182
procglobalstart = (u64Int *)calloc(nproc,sizeof(u64Int));
183
procglobalstart[me]=myglobalstart;
185
armci_msg_lgop(procglobalstart,nproc,"+");
186
#elif SIZEOF_LONG_LONG == 8
187
armci_msg_llgop(procglobalstart,nproc,"+");
189
# error could not determine 64bit integer type
192
armcismpid[i] = armci_clus_id(i);
193
HPCC_Table = (u64Int **)malloc(sizeof(u64Int *)*nproc);
194
if(HPCC_Table == NULL)
195
ARMCI_Error("initialize_tables:Table pointer malloc failed",(mytablelen*sizeof(u64Int)));
196
if(rc=ARMCI_Malloc((void **)HPCC_Table,mytablelen*sizeof(u64Int)))
197
ARMCI_Error("initialize_tables:Global Table malloc failed",(mytablelen*sizeof(u64Int)));
198
for(i=0;i<mytablelen;i++){
199
HPCC_Table[me][i] = i + myglobalstart;
201
vec_dscr = (struct vector_dscr_t *)malloc(sizeof(struct vector_dscr_t)*nsmp);
203
ARMCI_Error("initialize_tables:vec_dscr malloc fail",sizeof(struct vector_dscr_t)*nsmp);
205
vec_dscr[i].next=NULL;
206
vec_dscr[i].active=0;
207
vec_dscr[i].xmitbuffer = (u64Int **)malloc(sizeof(u64Int *)*nproc);
208
if(vec_dscr[i].xmitbuffer == NULL)
209
ARMCI_Error("initialize_tables:xmitbuffer malloc failed",sizeof(u64Int *)*nproc);
210
if(rc=ARMCI_Malloc((void **)vec_dscr[i].xmitbuffer,MAX_TOTAL_PENDING_UPDATES*sizeof(u64Int)))
211
ARMCI_Error("initialize_tables:xmitbuffer armci_malloc failed",sizeof(u64Int)*MAX_TOTAL_PENDING_UPDATES);
212
vec_dscr[i].dstproc = armci_smp_master(i);
213
vec_dscr[i].dstsmp = i;
214
vec_dscr[i].a_v.src_ptr_array=(void **)malloc(sizeof(void *)*MAX_TOTAL_PENDING_UPDATES);
215
for(j=0;j<MAX_TOTAL_PENDING_UPDATES;j++)
216
vec_dscr[i].a_v.src_ptr_array[j]=(void *)(vec_dscr[i].xmitbuffer[me]+j);
218
vec_dscr[i].a_v.dst_ptr_array=(void **)malloc(sizeof(void *)*MAX_TOTAL_PENDING_UPDATES);
219
if(vec_dscr[i].a_v.src_ptr_array==NULL || vec_dscr[i].a_v.dst_ptr_array==NULL)
220
ARMCI_Error("initialize_tables:.src_ptr_array malloc fail",sizeof(void *)*MAX_TOTAL_PENDING_UPDATES);
221
vec_dscr[i].a_v.ptr_array_len = 0;
222
vec_dscr[i].a_v.bytes = 8;
227
static void finalize_tables()
229
ARMCI_Free(HPCC_Table[me]);
239
double CPUTime; /* CPU time to update table */
240
double RealTime; /* Real time to update table */
245
u64Int NumUpdates; /* actual number of updates to table */
246
s64Int ProcNumUpdates; /* number of updates per processor */
248
FILE *outFile = NULL;
250
double max_time,min_time,avg_time,time_start,time_stop,total_time;
252
armci_msg_init(&argc,&argv);
253
nproc = armci_msg_nproc();
255
ARMCI_Init(); /* initialize ARMCI */
257
if(me==0)printf("\n RANDOM ACCESS EXAMPLE\n");
260
printf(" CORRECT USAGE IS:");
261
printf("\n\n <launch commands> simple.x inpfile\n");
265
armci_msg_finalize();
268
globaltablelen = atoi(argv[1]);
270
mintablesize = globaltablelen/nproc;
271
Remainder = globaltablelen - mintablesize*nproc;
272
bigtables = (mintablesize+1)*Remainder;
274
mytablelen = mintablesize+1;
275
myglobalstart = mytablelen*me;
278
mytablelen = mintablesize;
279
myglobalstart = mytablelen*me+Remainder;
281
procnumupdates = 4*mytablelen;
283
printf("\n%d:%d is totaltable, mintablesize=%d rem=%d big=%d glosta=%d tablelen=%d numup=%d\n",me, globaltablelen, mintablesize,Remainder,bigtables,myglobalstart,mytablelen,procnumupdates);
289
if(me==0)printf("\n\nStarting Random Access....");
292
time_start=armci_timer();
294
time_stop=armci_timer();
296
total_time=(time_stop-time_start);
300
armci_msg_dgop(&max_time,1,"max");
301
armci_msg_dgop(&min_time,1,"min");
302
armci_msg_dgop(&avg_time,1,"+");
304
if(me==0)printf("\nGUPs = %.9f %.9f %.9f Billion(10^9) Updates/PE per second [GUP/s]\n",1e-9*procnumupdates/max_time,1e-9*procnumupdates/min_time,1e-9*procnumupdates/avg_time);
307
if(me==0)printf("Terminating ..\n");
309
armci_msg_finalize();