| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the Zoltan contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
/* Program tests the Zoltan Distributed Directory software (stand-alone mode). |
| 11 |
*/ |
| 12 |
|
| 13 |
#include <mpi.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include <stdio.h> |
| 16 |
#include "zoltan_dd_cpp.h" |
| 17 |
#include "zoltan_mem.h" |
| 18 |
#include "zoltan_util.h" |
| 19 |
#include "zoltan_id.h" |
| 20 |
#include "zoltan_align.h" |
| 21 |
|
| 22 |
#ifdef __cplusplus |
| 23 |
/* if C++, define the rest of this header file as extern C */ |
| 24 |
extern "C" { |
| 25 |
#endif |
| 26 |
|
| 27 |
|
| 28 |
#define DD_TEST_NAME_NUMERIC 100 /* arbitrary starting value for defines */ |
| 29 |
#define NO_PROC -1 |
| 30 |
|
| 31 |
|
| 32 |
typedef struct |
| 33 |
{ |
| 34 |
int old_owner; |
| 35 |
int new_owner; /* old != new ==> simultated data move */ |
| 36 |
int partition; |
| 37 |
ZOLTAN_ID_TYPE id[1]; /* malloc'd beyond end of struct */ |
| 38 |
/* ZOLTAN_ID_TYPE lid[] at gid + glen */ |
| 39 |
/* ZOLTAN_ID_TYPE user[] at gid + glen + llen */ |
| 40 |
} Data; |
| 41 |
|
| 42 |
|
| 43 |
typedef struct |
| 44 |
{ |
| 45 |
int count; /* number of global IDs to simulate */ |
| 46 |
int pdelete; /* fraction of GIDs removed per cycle x100 */ |
| 47 |
int pmove; /* fraction of GIDs moved per cycle x100 */ |
| 48 |
int pscatter; /* fraction of GIDs scattered per cycle x 100 */ |
| 49 |
int nloops; /* number of times to loop though simulation */ |
| 50 |
int rseed; /* seed for random number generator */ |
| 51 |
|
| 52 |
int glen; /* global ID length */ |
| 53 |
int llen; /* local ID length */ |
| 54 |
int ulen; /* user data ID length */ |
| 55 |
int tlen; /* hash table length */ |
| 56 |
int slen; /* length of Data * id stuff */ |
| 57 |
|
| 58 |
int name_scheme; |
| 59 |
int debug_level; |
| 60 |
} Param; |
| 61 |
|
| 62 |
|
| 63 |
static int get_params (Param *p); |
| 64 |
|
| 65 |
static int initialize_data (Param *p, char *store, int nproc); |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
int main (int argc, char *argv[]) |
| 74 |
{ |
| 75 |
Zoltan_DD *dd; |
| 76 |
|
| 77 |
int myproc; /* MPI rank, my processor's MPI ID */ |
| 78 |
int nproc; /* MPI size, number of processors */ |
| 79 |
ZOLTAN_ID_PTR glist = NULL; /* list of GIDs */ |
| 80 |
ZOLTAN_ID_PTR llist = NULL; /* list of LIDs */ |
| 81 |
ZOLTAN_ID_PTR ulist = NULL; /* list of user data of type |
| 82 |
ZOLTAN_ID_TYPE */ |
| 83 |
int *plist = NULL; /* list of partitions */ |
| 84 |
int *olist = NULL; /* list of owners */ |
| 85 |
Param param; /* program's adjustable parameters */ |
| 86 |
char *store = NULL; /* non directory storage of test data */ |
| 87 |
Data *data = NULL; /* pointer into store */ |
| 88 |
|
| 89 |
/* these are all temporary variables: */ |
| 90 |
int new_owner; |
| 91 |
int count; |
| 92 |
int i; |
| 93 |
char *p; |
| 94 |
int err; |
| 95 |
int errcount; |
| 96 |
int loop; |
| 97 |
|
| 98 |
|
| 99 |
char str[100]; /* for building output messages */ |
| 100 |
char *yo = "DD_Main"; |
| 101 |
|
| 102 |
|
| 103 |
/* initialize MPI communications, ignore errors */ |
| 104 |
MPI_Init (&argc, &argv); |
| 105 |
MPI_Comm_rank (MPI_COMM_WORLD, &myproc); |
| 106 |
MPI_Comm_size (MPI_COMM_WORLD, &nproc); |
| 107 |
|
| 108 |
get_params (¶m); /* read input parameters */ |
| 109 |
|
| 110 |
dd = new Zoltan_DD( MPI_COMM_WORLD, param.glen, param.llen, |
| 111 |
param.ulen*sizeof(ZOLTAN_ID_TYPE), param.tlen, param.debug_level); |
| 112 |
|
| 113 |
param.slen = sizeof (Data) |
| 114 |
+ (param.glen + param.llen + param.ulen) * sizeof(ZOLTAN_ID_TYPE); |
| 115 |
param.slen = Zoltan_Align(param.slen); |
| 116 |
store = (char *) ZOLTAN_MALLOC (param.count * param.slen); |
| 117 |
|
| 118 |
/* allocate storage for various lists */ |
| 119 |
glist = (ZOLTAN_ID_PTR) ZOLTAN_MALLOC (sizeof(ZOLTAN_ID_TYPE) * param.count |
| 120 |
* param.glen); |
| 121 |
plist = (int *) ZOLTAN_MALLOC (sizeof (int) * param.count); |
| 122 |
olist = (int *) ZOLTAN_MALLOC (sizeof (int) * param.count); |
| 123 |
if (param.llen != 0) |
| 124 |
llist = (ZOLTAN_ID_PTR) ZOLTAN_MALLOC (sizeof (ZOLTAN_ID_TYPE) * |
| 125 |
param.count * param.llen); |
| 126 |
if (param.ulen != 0) |
| 127 |
ulist = (ZOLTAN_ID_PTR) ZOLTAN_MALLOC (sizeof (ZOLTAN_ID_TYPE) * |
| 128 |
param.count * param.ulen); |
| 129 |
|
| 130 |
|
| 131 |
if (store == NULL || glist == NULL |
| 132 |
|| (param.llen != 0 && llist == NULL) |
| 133 |
|| (param.ulen != 0 && ulist == NULL) |
| 134 |
|| plist == NULL || olist == NULL) { |
| 135 |
ZOLTAN_PRINT_ERROR (myproc, yo, "Unable to malloc storage lists"); |
| 136 |
return 1; |
| 137 |
} |
| 138 |
|
| 139 |
initialize_data (¶m, store, nproc); |
| 140 |
|
| 141 |
/* create & update directory with myproc's initial simulated GIDs */ |
| 142 |
count = 0; |
| 143 |
for (p = store; p < store + param.count * param.slen; p += param.slen) |
| 144 |
if (((Data *)p)->new_owner == myproc) { |
| 145 |
ZOLTAN_SET_ID (param.glen, glist + count * param.glen, |
| 146 |
((Data *)p)->id); |
| 147 |
if (param.llen) |
| 148 |
ZOLTAN_SET_ID (param.llen, llist + count * param.llen, |
| 149 |
((Data *)p)->id + param.glen); |
| 150 |
if (param.ulen) |
| 151 |
ZOLTAN_SET_ID (param.ulen, ulist + count * param.ulen, |
| 152 |
((Data *)p)->id + (param.glen + param.llen)); |
| 153 |
plist [count] = ((Data *)p)->partition; |
| 154 |
count++; |
| 155 |
} |
| 156 |
err = dd->Update (glist, llist, (char *)ulist, plist, count); |
| 157 |
if (err != ZOLTAN_DD_NORMAL_RETURN) |
| 158 |
ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Update"); |
| 159 |
|
| 160 |
i = 0; |
| 161 |
for (p = store; p < store + param.count * param.slen; p += param.slen) { |
| 162 |
ZOLTAN_SET_ID (param.glen, glist + i * param.glen, ((Data *)p)->id); |
| 163 |
i++; |
| 164 |
} |
| 165 |
err = dd->Find (glist, llist, (char *)ulist, plist, param.count, olist); |
| 166 |
if (err != ZOLTAN_DD_NORMAL_RETURN) |
| 167 |
ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Find"); |
| 168 |
|
| 169 |
errcount = 0; |
| 170 |
for (i = 0; i < param.count; i++) |
| 171 |
if (olist[i] != ((Data *) (store + i * param.slen))->new_owner) |
| 172 |
errcount++; |
| 173 |
if (errcount > 0) |
| 174 |
sprintf (str, "FIRST TEST FAILED, errcount is %d", errcount); |
| 175 |
else |
| 176 |
sprintf (str, "FIRST TEST SUCCESSFUL"); |
| 177 |
ZOLTAN_PRINT_INFO (myproc, yo, str); |
| 178 |
|
| 179 |
/* repeatedly simulate moving "dots" around the system */ |
| 180 |
for (loop = 0; loop < param.nloops; loop++) { |
| 181 |
for (p = store; p < store + param.count * param.slen; p += param.slen) |
| 182 |
((Data *) p)->old_owner = ((Data *) p)->new_owner; |
| 183 |
|
| 184 |
/* randomly exchange some dots and randomly reassign others */ |
| 185 |
for (i = 0; i < (param.pmove * param.count)/100; i++) { |
| 186 |
Data *d1, *d2; |
| 187 |
d1 = (Data *) (store + param.slen * (rand() % param.count)); |
| 188 |
d2 = (Data *) (store + param.slen * (rand() % param.count)); |
| 189 |
new_owner = d1->new_owner; |
| 190 |
d1->new_owner = d2->new_owner; |
| 191 |
d2->new_owner = new_owner; |
| 192 |
} |
| 193 |
|
| 194 |
for (i = 0; i < (param.count * param.pscatter)/100; i++) |
| 195 |
((Data *) (store + param.slen *(rand() % param.count)))->new_owner |
| 196 |
= rand() % nproc; |
| 197 |
|
| 198 |
/* determine which new GIDs myproc gained, and update directory */ |
| 199 |
count = 0; |
| 200 |
for (p = store; p < store + param.count * param.slen; p += param.slen) |
| 201 |
if (((Data *)p)->new_owner == myproc) { |
| 202 |
((Data *)p)->id[param.glen] = count; /* set LID */ |
| 203 |
ZOLTAN_SET_ID (param.glen, glist + count * param.glen, |
| 204 |
((Data *)p)->id); |
| 205 |
if (param.llen) |
| 206 |
ZOLTAN_SET_ID (param.llen, llist + count * param.llen, |
| 207 |
((Data *)p)->id + param.glen); |
| 208 |
if (param.ulen) |
| 209 |
ZOLTAN_SET_ID (param.ulen, ulist + count * param.ulen, |
| 210 |
((Data *)p)->id + (param.glen + param.llen)); |
| 211 |
plist [count] = ((Data *)p)->partition; |
| 212 |
count++; |
| 213 |
} |
| 214 |
err = dd->Update (glist, llist, (char *)ulist, plist, count); |
| 215 |
if (err != ZOLTAN_DD_NORMAL_RETURN) |
| 216 |
ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Update"); |
| 217 |
|
| 218 |
/* use directory to "find" GIDs */ |
| 219 |
i = 0; |
| 220 |
for (p = store; p < store + param.count * param.slen; p += param.slen) { |
| 221 |
ZOLTAN_SET_ID (param.glen, glist + i * param.glen, ((Data *)p)->id); |
| 222 |
i++; |
| 223 |
} |
| 224 |
err = dd->Find (glist, llist, (char *)ulist, plist, param.count, olist); |
| 225 |
if (err != ZOLTAN_DD_NORMAL_RETURN) |
| 226 |
ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Find"); |
| 227 |
|
| 228 |
errcount = 0; |
| 229 |
for (i = 0; i < param.count; i++) |
| 230 |
if (olist[i] != ((Data *)(store + i * param.slen))->new_owner) |
| 231 |
errcount++; |
| 232 |
if (errcount > 0) |
| 233 |
sprintf (str, "LOOP %d TEST FAILED, errcount is %d", loop, errcount); |
| 234 |
else |
| 235 |
sprintf (str, "LOOP %d TEST SUCCESSFUL", loop); |
| 236 |
ZOLTAN_PRINT_INFO (myproc, yo, str); |
| 237 |
|
| 238 |
|
| 239 |
/* randomly remove a percentage of GIDs from the directory */ |
| 240 |
count = 0; |
| 241 |
for (i = 0; i < (param.count * param.pdelete)/100; i++) { |
| 242 |
data = (Data *) (store + param.slen * (rand() % param.count)); |
| 243 |
|
| 244 |
if (data->new_owner == myproc) { |
| 245 |
ZOLTAN_SET_ID (param.glen, glist + count * param.glen, data->id); |
| 246 |
count++; |
| 247 |
} |
| 248 |
data->new_owner = NO_PROC; |
| 249 |
} |
| 250 |
err = dd->Remove (glist, count); |
| 251 |
if (err != ZOLTAN_DD_NORMAL_RETURN) |
| 252 |
ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Remove"); |
| 253 |
|
| 254 |
|
| 255 |
/* update directory (put directory entries back in) */ |
| 256 |
for (p = store; p < store + param.count * param.slen; p += param.slen) |
| 257 |
if (((Data *)p)->new_owner == NO_PROC) |
| 258 |
((Data *)p)->new_owner = loop % nproc; /* place in new location */ |
| 259 |
|
| 260 |
count = 0; |
| 261 |
for (p = store; p < store + param.count * param.slen; p += param.slen) |
| 262 |
if (((Data *)p)->new_owner == myproc) { |
| 263 |
ZOLTAN_SET_ID (param.glen, glist + count * param.glen, |
| 264 |
((Data *)p)->id); |
| 265 |
if (param.llen) |
| 266 |
ZOLTAN_SET_ID (param.llen, llist + count * param.llen, |
| 267 |
((Data *)p)->id + param.glen); |
| 268 |
if (param.ulen) |
| 269 |
ZOLTAN_SET_ID (param.ulen, ulist + count * param.ulen, |
| 270 |
((Data *)p)->id + (param.glen + param.llen)); |
| 271 |
plist [count] = ((Data *)p)->partition; |
| 272 |
count++; |
| 273 |
} |
| 274 |
err = dd->Update (glist, NULL, NULL, NULL, count); |
| 275 |
if (err != ZOLTAN_DD_NORMAL_RETURN) |
| 276 |
ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Update"); |
| 277 |
} |
| 278 |
|
| 279 |
/* now Find directory info for GIDs myproc now owns and validate */ |
| 280 |
count = 0; |
| 281 |
for (i = 0; i < param.count; i++) { |
| 282 |
data = (Data *) (store + i * param.slen); |
| 283 |
if (data->new_owner == myproc) { |
| 284 |
ZOLTAN_SET_ID (param.glen, glist + count * param.glen, data->id); |
| 285 |
count++; |
| 286 |
} |
| 287 |
} |
| 288 |
err = dd->Find (glist, NULL, NULL, NULL, count, olist); |
| 289 |
if (err != ZOLTAN_DD_NORMAL_RETURN) |
| 290 |
ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Find"); |
| 291 |
|
| 292 |
errcount = 0; |
| 293 |
for (i = 0; i < count; i++) |
| 294 |
if (olist[i] != myproc) |
| 295 |
errcount++; |
| 296 |
if (errcount > 0) { |
| 297 |
sprintf (str, "errcount is %d", errcount); |
| 298 |
ZOLTAN_PRINT_ERROR (myproc, yo, str); |
| 299 |
} |
| 300 |
else |
| 301 |
ZOLTAN_PRINT_INFO (myproc, yo, "TEST SUCCESSFUL"); |
| 302 |
|
| 303 |
dd->Stats (); |
| 304 |
|
| 305 |
/* done, now free memory, stop MPI & directory, return */ |
| 306 |
ZOLTAN_FREE (&store); |
| 307 |
ZOLTAN_FREE (&glist); |
| 308 |
ZOLTAN_FREE (&plist); |
| 309 |
ZOLTAN_FREE (&olist); |
| 310 |
|
| 311 |
if (param.llen != 0) ZOLTAN_FREE (&llist); |
| 312 |
if (param.ulen != 0) ZOLTAN_FREE (&ulist); |
| 313 |
|
| 314 |
ZOLTAN_PRINT_INFO (myproc, yo, "Completing program"); |
| 315 |
|
| 316 |
delete dd; |
| 317 |
|
| 318 |
MPI_Finalize (); |
| 319 |
return 0; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
static int initialize_data (Param *param, char *store, int nproc) |
| 329 |
{ |
| 330 |
int i; |
| 331 |
int j; |
| 332 |
Data *data; |
| 333 |
|
| 334 |
if (param->name_scheme == DD_TEST_NAME_NUMERIC) |
| 335 |
{ |
| 336 |
for (i = 0; i < param->count; i++) |
| 337 |
{ |
| 338 |
data = (Data *) (store + i * param->slen); |
| 339 |
for (j = 0; j < param->glen; j++) |
| 340 |
data->id[j] = (ZOLTAN_ID_TYPE) i; |
| 341 |
|
| 342 |
for (j = 0; j < param->llen; j++) |
| 343 |
data->id[j + param->glen] = (ZOLTAN_ID_TYPE) (i % nproc); |
| 344 |
|
| 345 |
for (j = 0; j < param->ulen; j++) |
| 346 |
data->id[j + param->glen + param->llen] = |
| 347 |
(ZOLTAN_ID_TYPE) (i % nproc); |
| 348 |
|
| 349 |
data->partition = i % 7; |
| 350 |
data->new_owner = i % nproc; |
| 351 |
data->old_owner = i % nproc; |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
srand ((unsigned int) param->rseed); |
| 356 |
|
| 357 |
return 0; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
static int get_params (Param *param) |
| 364 |
{ |
| 365 |
/* establish default values */ |
| 366 |
/* param->count = 250000; KDD */ /* 1500000; */ |
| 367 |
param->count = 2000; /* 1500000; */ |
| 368 |
param->pmove = 10; |
| 369 |
param->pdelete = 3; |
| 370 |
param->pscatter = 4; |
| 371 |
/* param->nloops = 200; KDD */ |
| 372 |
param->nloops = 20; |
| 373 |
|
| 374 |
param->glen = 5; |
| 375 |
param->llen = 5; |
| 376 |
param->ulen = 10; |
| 377 |
param->tlen = 5000; |
| 378 |
|
| 379 |
/* param->debug_level = 1; KDD */ |
| 380 |
param->debug_level = 3; |
| 381 |
param->name_scheme = DD_TEST_NAME_NUMERIC; |
| 382 |
|
| 383 |
param->rseed = 31415926; |
| 384 |
|
| 385 |
/* read external file for optional non default parameter values */ |
| 386 |
|
| 387 |
return 0; |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
#ifdef __cplusplus |
| 392 |
} /* closing bracket for extern "C" */ |
| 393 |
#endif |