Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kaHIP k-way partitioning #231

Merged
merged 10 commits into from
Jul 26, 2022
Merged

Conversation

mgsium
Copy link
Collaborator

@mgsium mgsium commented Jul 14, 2022

No description provided.

@reguly
Copy link
Collaborator

reguly commented Jul 15, 2022

It looks like currently if you have both parmetis and kahip, and as for kway, kahip will be used, and there is no way to get parmetis. Please allow the use of both. In the call to op_partition, you can specify both combinations, so it's just a matter of propagating this information into op_partition_kway

Copy link
Collaborator

@reguly reguly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some compilation issues when I have Parmetis and kahip. Goes through OK if I only have KaHIP.

KAHIP_DEF ?= -DHAVE_KAHIP

ifdef KAHIP_INSTALL_PATH
KAHIP_INC_PATH := -I$(KAHIP_INSTALL_PATH)/parallel/parallel_src/interface \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be -I$(KAHIP_INSTALL_PATH)/include
if the kahip library is properly "installed" i.e. during compilation you have -DCMAKE_INSTALL_PREFIX=somedir then during OP2 make config you have KAHIP_INSTALL_PATH=somedir

ifdef KAHIP_INSTALL_PATH
KAHIP_INC_PATH := -I$(KAHIP_INSTALL_PATH)/parallel/parallel_src/interface \
-I$(KAHIP_INSTALL_PATH)/interface
KAHIP_LIB_PATH := -L$(KAHIP_INSTALL_PATH)/build/parallel/parallel_src \
Copy link
Collaborator

@reguly reguly Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with LIB_PATH - should be -L$(KAHIP_INSTALL_PATH)/lib

#ifdef HAVE_KAHIP
#include <parhip_interface.h>

typedef idxtype idx_t;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting a compile time error with gcc 9 if I also have ParMetis installed:

In file included from src/mpi/op_mpi_part_core.cpp:73:
/home/shared/software/kahip-ompi401/include/parhip_interface.h:15:28: error: conflicting declaration ‘typedef long long unsigned int idxtype’
15 | typedef unsigned long long idxtype;
| ^~~~~~~
src/mpi/op_mpi_part_core.cpp:65:15: note: previous declaration as ‘typedef idx_t idxtype’
65 | typedef idx_t idxtype;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into the same issue yesterday, looks like ParMETIS defines idx_t while ParHIP defines idxtype, which is distinct. As long as only one of the two are installed, we can use typedef to set the type as necessary but with both installed we're forced to choose between the types at runtime.

The interface for the two k-way partition functions are very similar apart from this type issue so I'm reluctant to define another op_partition_kway just for the ParHIP version. But I've yet to find an elegant solution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a tough one... My first idea, while being wasteful, but at least compact, would be to pass the parmetis-style arrays to a function, and allocate new ones with kahip types, convert them, then call kahip. Which is indeed ugly! But the fundamental issue is that even if both use 64 bits, kahip uses unsigned, whereas parmetis signed...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we define a generic op_partition_kway_generic outside the scope of extern "C", then call this from op_partition_kway. Afaik this remains C-compatible if we just expose the signature of op_partition_kway with extern "C", and keep the body outside?

@reguly
Copy link
Collaborator

reguly commented Jul 20, 2022 via email

@mgsium
Copy link
Collaborator Author

mgsium commented Jul 20, 2022

I think some overloading is still necessary because the two partition functions don't take the same arguments. The best I could think of was:

/*******************************************************************************
 * Generic wrapper for kway-partition functions
 *******************************************************************************/

template <class T>
void do_partition(T *vtxdist, T *xadj, T *adjncy, T *wgtflag, T *numflag, 
            T *ncon, T *nparts,real_t *tpwgts, real_t *ubvec, T *options, 
            T *edgecut, T *part, MPI_Comm *comm) {}

#ifdef HAVE_PARMETIS
template<> void do_partition<idx_t>(idx_t *vtxdist, idx_t *xadj, idx_t *adjncy, 
            idx_t *wgtflag, idx_t *numflag, idx_t *ncon, idx_t *nparts,real_t *tpwgts, 
            real_t *ubvec, idx_t *options, idx_t *edgecut, idx_t *part, MPI_Comm *comm) {
  ParMETIS_V3_PartKway( vtxdist, xadj, adjncy, NULL, NULL, wgtflag, numflag, ncon, 
                        nparts, tpwgts, ubvec, options, edgecut, part, comm);
}
#endif

#ifdef HAVE_KAHIP
template<> void do_partition<idxtype>(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, 
            idxtype *wgtflag, idxtype *numflag, idxtype *ncon, idxtype *nparts, real_t *tpwgts, 
            real_t *ubvec, idxtype *options, idxtype *edgecut, idxtype *part, MPI_Comm *comm) {
  double imb = 0.03;
  ParHIPPartitionKWay( vtxdist, xadj, adjncy, NULL, NULL, (int*) nparts, &imb, 
                       false, 1, ULTRAFASTMESH, (int*) edgecut, part, comm);
}
#endif

The long argument list is a little ugly (although it can be made a little better by omitting the names of unused arguments).
Not an ideal solution but it feels less cumbersome than overloading op_partition_kway.

@reguly
Copy link
Collaborator

reguly commented Jul 20, 2022 via email

@mgsium
Copy link
Collaborator Author

mgsium commented Jul 20, 2022

I'm doing that too, but there's still the problem of choosing whether to call the kahip or parmetis function at runtime.

@mgsium
Copy link
Collaborator Author

mgsium commented Jul 21, 2022

On second thoughts, do_partition doesn't need to be templated. This should suffice:

#ifdef HAVE_PARMETIS
void do_partition(idx_t *vtxdist, idx_t *xadj, ...) {
  ParMETIS_V3_PartKway( vtxdist, xadj, adjncy, NULL, NULL, wgtflag, numflag, ncon, 
                        nparts, tpwgts, ubvec, options, edgecut, part, comm);
}
#endif

#ifdef HAVE_KAHIP
void do_partition(idxtype *vtxdist, idxtype *xadj, ...) {
  double imb = 0.03;
  ParHIPPartitionKWay( vtxdist, xadj, adjncy, NULL, NULL, (int*) nparts, &imb, 
                       false, 1, ULTRAFASTMESH, (int*) edgecut, part, comm);
}
#endif

@reguly
Copy link
Collaborator

reguly commented Jul 21, 2022

let's see :)

Copy link
Collaborator

@reguly reguly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiles and works!

@mgsium
Copy link
Collaborator Author

mgsium commented Jul 21, 2022

Great! I'll just change the include and library paths and that should be it

@gihanmudalige
Copy link
Collaborator

@reguly thanks for following up on this. Seems @mgsium has completed the work in record time !

@mgsium I assume this is now working with the Makefile system in the master branch ?
If we are to merge this I think it would be good to add some documentation on the new capabilities. For example adding details to : https://op2-dsl.readthedocs.io/en/latest/api.html?highlight=partition#c.op_partition
Furthermore if there is a need to have any runtime flags to activate this partiotioner capabilities, that needs to be documented as well. Finally have you checked the coding standards and run it through git clang-format ?

Thanks.

@bozbez
Copy link
Collaborator

bozbez commented Jul 21, 2022

The Makefiles look good to me.
Once this is merged it would also be worth updating the spack recipe.

@mgsium mgsium marked this pull request as ready for review July 22, 2022 12:06
@mgsium
Copy link
Collaborator Author

mgsium commented Jul 22, 2022

@gihanmudalige I updated the docs and ran clang-format on the changes. I've been using the Makefile to build and test so all should be good there.

@gihanmudalige gihanmudalige merged commit fba5c05 into OP-DSL:master Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants