//  run with MPI:  ff-mpirun -np 4 script.edp
// NBPROC 4

include "getARGV.idp"
load "metis"
load "parmetis"

mesh Th = square(getARGV("-global", 800), getARGV("-global", 800));
fespace Ph(Th, P0);
{
    mpiBarrier(mpiCommWorld);
    real time = mpiWtime();
    Ph part;
    if(mpirank == 0)
        metisdual(part[], Th, getARGV("-lpart", 128));
    broadcast(processor(0, mpiCommWorld), part[]);
    mpiBarrier(mpiCommWorld);
    if(mpirank == 0) {
        cout << "METIS: " << mpiWtime() - time << endl;
        plot(part, wait = 1, fill = 1, cmm = "METIS");
    }
}
{
    mpiBarrier(mpiCommWorld);
    real time = mpiWtime();
    Ph part;
    parmetis(part[], Th, getARGV("-lpart", 128), communicator = mpiCommWorld, worker = getARGV("-worker", mpisize));
    mpiBarrier(mpiCommWorld);
    if(mpirank == 0) {
        cout << "ParMETIS: " << mpiWtime() - time << endl;
        plot(part, wait = 1, fill = 1, cmm = "ParMETIS");
    }
}
