| 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 |
// // |
| 11 |
// File: driver.cc // |
| 12 |
// Project: Local HSFC Ordering // |
| 13 |
// Author: Michael Wolf // |
| 14 |
// Date Started: 11/02/2009 // |
| 15 |
// // |
| 16 |
// Description: // |
| 17 |
// File tests local HSFC ordering for simple test problem // |
| 18 |
// // |
| 19 |
// $Id: driver.cc 19 2009-12-18 17:52:36Z mmwolf $ // |
| 20 |
////////////////////////////////////////////////////////////////////////////// |
| 21 |
#include "Zoltan_config.h" |
| 22 |
|
| 23 |
#ifdef HAVE_MPI |
| 24 |
#include <mpi.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <iostream> |
| 28 |
#include <math.h> |
| 29 |
#include <vector> |
| 30 |
#include <set> |
| 31 |
#include <iterator> |
| 32 |
#include <list> |
| 33 |
#include <stdlib.h> |
| 34 |
|
| 35 |
|
| 36 |
extern "C" { |
| 37 |
#include <zoltan.h> |
| 38 |
#include <zoltan_types.h> |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
#define SUCCESS 0 |
| 43 |
#define FAIL 1 |
| 44 |
|
| 45 |
int locNumObj = 16; //number of objects locally |
| 46 |
|
| 47 |
unsigned int answers[4][16] = {{12, 8, 9, 13, 14, 15, 11, 10, 6, 7, 3, 2, 1, 5, 4, 0}, |
| 48 |
{28, 24, 25, 29, 30, 31, 27, 26, 22, 23, 19, 18, 17, 21, 20, 16}, |
| 49 |
{44, 40, 41, 45, 46, 47, 43, 42, 38, 39, 35, 34, 33, 37, 36, 32}, |
| 50 |
{60, 56, 57, 61, 62, 63, 59, 58, 54, 55, 51, 50, 49, 53, 52, 48}}; |
| 51 |
|
| 52 |
int order(int worldsize, int myrank); |
| 53 |
int checkResults(int myrank, ZOLTAN_ID_PTR permGIDs); |
| 54 |
|
| 55 |
////////////////////////////////////////////////////////////// |
| 56 |
// Zoltan query functions |
| 57 |
////////////////////////////////////////////////////////////// |
| 58 |
int zoltNumObjs(void *data,int *ierr); |
| 59 |
|
| 60 |
void zoltGetObjs(void *data, int num_gid_entries, |
| 61 |
int num_lid_entries, ZOLTAN_ID_PTR global_ids, |
| 62 |
ZOLTAN_ID_PTR local_ids, int wgt_dim, |
| 63 |
float *obj_wgts, int *ierr); |
| 64 |
int zoltNumGeom(void *data,int *ierr); |
| 65 |
void zoltGeom(void *data, int num_gid_entries, int num_lid_entries, ZOLTAN_ID_PTR global_id, |
| 66 |
ZOLTAN_ID_PTR local_id, double *geom_vec, int *ierr); |
| 67 |
////////////////////////////////////////////////////////////////// |
| 68 |
|
| 69 |
////////////////////////////////////////////////////////////////////////////// |
| 70 |
////////////////////////////////////////////////////////////////////////////// |
| 71 |
int main(int argc, char *argv[]) |
| 72 |
{ |
| 73 |
float ver; |
| 74 |
|
| 75 |
#ifdef HAVE_MPI |
| 76 |
MPI_Init(&argc,&argv); |
| 77 |
#endif |
| 78 |
|
| 79 |
Zoltan_Initialize(argc,argv,&ver); //initialize Zoltan |
| 80 |
|
| 81 |
int worldsize, myrank; |
| 82 |
|
| 83 |
#ifdef HAVE_MPI |
| 84 |
MPI_Comm_size(MPI_COMM_WORLD,&worldsize); |
| 85 |
MPI_Comm_rank(MPI_COMM_WORLD,&myrank); |
| 86 |
#else |
| 87 |
worldsize = 1; |
| 88 |
myrank = 0; |
| 89 |
#endif |
| 90 |
|
| 91 |
if(worldsize!=1 && worldsize!=2 && worldsize!=4) |
| 92 |
{ |
| 93 |
#ifdef HAVE_MPI |
| 94 |
MPI_Finalize(); |
| 95 |
#endif |
| 96 |
|
| 97 |
if(myrank==0) |
| 98 |
{ |
| 99 |
std::cout << "WARNING for testPartitionMVInput() with number of processors = " << worldsize << std::endl |
| 100 |
<< " Number of processes not supported .... (by default) returning success" << std::endl; |
| 101 |
} |
| 102 |
|
| 103 |
return SUCCESS; |
| 104 |
} |
| 105 |
|
| 106 |
int retFlag = 0; |
| 107 |
|
| 108 |
retFlag = order(worldsize,myrank); |
| 109 |
|
| 110 |
#ifdef HAVE_MPI |
| 111 |
MPI_Finalize(); |
| 112 |
#endif |
| 113 |
|
| 114 |
if (retFlag==0) |
| 115 |
{ |
| 116 |
return FAIL; |
| 117 |
} |
| 118 |
|
| 119 |
return SUCCESS; |
| 120 |
} |
| 121 |
////////////////////////////////////////////////////////////////////////////// |
| 122 |
|
| 123 |
////////////////////////////////////////////////////////////////////////////// |
| 124 |
////////////////////////////////////////////////////////////////////////////// |
| 125 |
int order(int worldsize, int myrank) |
| 126 |
{ |
| 127 |
struct Zoltan_Struct *zz; |
| 128 |
|
| 129 |
// sprintf(paramPartitions,"%d",numprocs); |
| 130 |
|
| 131 |
zz = Zoltan_Create(MPI_COMM_WORLD); |
| 132 |
|
| 133 |
|
| 134 |
// General Zoltan Parameters |
| 135 |
Zoltan_Set_Param(zz,"ORDER_METHOD","LOCAL_HSFC"); |
| 136 |
//Zoltan_Set_Param(zz,"ORDER_START_INDEX","1"); |
| 137 |
|
| 138 |
|
| 139 |
// register query functions |
| 140 |
Zoltan_Set_Fn(zz, ZOLTAN_NUM_OBJ_FN_TYPE, (void (*)()) zoltNumObjs, 0); |
| 141 |
Zoltan_Set_Fn(zz, ZOLTAN_OBJ_LIST_FN_TYPE, (void (*)()) zoltGetObjs, 0); |
| 142 |
Zoltan_Set_Fn(zz, ZOLTAN_NUM_GEOM_FN_TYPE, (void (*)()) zoltNumGeom, 0); |
| 143 |
Zoltan_Set_Fn(zz, ZOLTAN_GEOM_FN_TYPE, (void (*)()) zoltGeom, 0); |
| 144 |
|
| 145 |
int numGidEntries=1; |
| 146 |
|
| 147 |
ZOLTAN_ID_PTR global_ids=0; |
| 148 |
ZOLTAN_ID_PTR permGIDs = 0; |
| 149 |
|
| 150 |
global_ids = new ZOLTAN_ID_TYPE[locNumObj]; |
| 151 |
permGIDs = new ZOLTAN_ID_TYPE[locNumObj]; |
| 152 |
|
| 153 |
for(int i=0;i<locNumObj; i++) |
| 154 |
{ |
| 155 |
global_ids[i]=16*myrank + (i+1); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
Zoltan_Order (zz, numGidEntries, locNumObj, global_ids, permGIDs); |
| 160 |
|
| 161 |
int successFlag = checkResults(myrank, permGIDs); |
| 162 |
|
| 163 |
int returnFlag; |
| 164 |
|
| 165 |
#ifdef HAVE_MPI |
| 166 |
MPI_Allreduce(&successFlag,&returnFlag,1,MPI_INT,MPI_LAND,MPI_COMM_WORLD); |
| 167 |
#else |
| 168 |
returnFlag = successFlag; |
| 169 |
#endif |
| 170 |
|
| 171 |
if(myrank==0) |
| 172 |
{ |
| 173 |
if(returnFlag == 1) |
| 174 |
{ |
| 175 |
std::cout << "Success in testing local HSFC ordering on simple problem, numProcs = " |
| 176 |
<< worldsize << std::endl; |
| 177 |
} |
| 178 |
else |
| 179 |
{ |
| 180 |
std::cout << "Failure in testing local HSFC ordering on simple problem, numProcs = " |
| 181 |
<< worldsize << std::endl; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
delete [] global_ids; |
| 186 |
delete [] permGIDs; |
| 187 |
Zoltan_Destroy(&zz); |
| 188 |
|
| 189 |
return returnFlag; |
| 190 |
} |
| 191 |
////////////////////////////////////////////////////////////////////////////// |
| 192 |
|
| 193 |
////////////////////////////////////////////////////////////////////////////// |
| 194 |
////////////////////////////////////////////////////////////////////////////// |
| 195 |
int checkResults(int myrank, ZOLTAN_ID_PTR permGIDs) |
| 196 |
{ |
| 197 |
for(int i=0;i<locNumObj; i++) |
| 198 |
{ |
| 199 |
if(permGIDs[i] != answers[myrank][i]) |
| 200 |
{ |
| 201 |
return 0; |
| 202 |
} |
| 203 |
} |
| 204 |
return 1; |
| 205 |
} |
| 206 |
////////////////////////////////////////////////////////////////////////////// |
| 207 |
|
| 208 |
////////////////////////////////////////////////////////////// |
| 209 |
////////////////////////////////////////////////////////////// |
| 210 |
int zoltNumObjs(void *data,int *ierr) |
| 211 |
{ |
| 212 |
*ierr=0; |
| 213 |
|
| 214 |
return locNumObj; |
| 215 |
} |
| 216 |
////////////////////////////////////////////////////////////// |
| 217 |
|
| 218 |
////////////////////////////////////////////////////////////// |
| 219 |
////////////////////////////////////////////////////////////// |
| 220 |
void zoltGetObjs(void *data, int num_gid_entries, |
| 221 |
int num_lid_entries, ZOLTAN_ID_PTR global_ids, |
| 222 |
ZOLTAN_ID_PTR local_ids, int wgt_dim, |
| 223 |
float *obj_wgts, int *ierr) |
| 224 |
{ |
| 225 |
int myrank; |
| 226 |
|
| 227 |
#ifdef HAVE_MPI |
| 228 |
MPI_Comm_rank(MPI_COMM_WORLD,&myrank); |
| 229 |
#else |
| 230 |
myrank=0; |
| 231 |
#endif |
| 232 |
|
| 233 |
for(int i=0;i<locNumObj;i++) |
| 234 |
{ |
| 235 |
global_ids[i]=16*myrank + (i+1); |
| 236 |
local_ids[i]=i+1; |
| 237 |
} |
| 238 |
|
| 239 |
*ierr=0; |
| 240 |
|
| 241 |
return; |
| 242 |
} |
| 243 |
////////////////////////////////////////////////////////////// |
| 244 |
|
| 245 |
////////////////////////////////////////////////////////////// |
| 246 |
////////////////////////////////////////////////////////////// |
| 247 |
int zoltNumGeom(void *data,int *ierr) |
| 248 |
{ |
| 249 |
return 2; |
| 250 |
} |
| 251 |
////////////////////////////////////////////////////////////// |
| 252 |
|
| 253 |
////////////////////////////////////////////////////////////// |
| 254 |
////////////////////////////////////////////////////////////// |
| 255 |
void zoltGeom(void *data, int num_gid_entries, int num_lid_entries, ZOLTAN_ID_PTR global_id, |
| 256 |
ZOLTAN_ID_PTR local_id, double *geom_vec, int *ierr) |
| 257 |
{ |
| 258 |
|
| 259 |
int myrank; |
| 260 |
|
| 261 |
#ifdef HAVE_MPI |
| 262 |
MPI_Comm_rank(MPI_COMM_WORLD,&myrank); |
| 263 |
#else |
| 264 |
myrank = 0; |
| 265 |
#endif |
| 266 |
|
| 267 |
geom_vec[0] = (double) ( 4*(((*global_id)-1)/32) + (((*global_id)-1)%4)+1); |
| 268 |
geom_vec[1] = (double) ((((*global_id)-1)%32)/4 + 1); |
| 269 |
|
| 270 |
*ierr=0; |
| 271 |
|
| 272 |
return; |
| 273 |
} |
| 274 |
////////////////////////////////////////////////////////////// |
| 275 |
|