Skip to content

Commit

Permalink
an attempt to make things work with MPICH
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Leykin committed May 5, 2023
1 parent 88e3d21 commit e01bbce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ jobs:
# TODO: add Macaulay2/tests/engine when https://github.com/Macaulay2/M2/issues/1213 is fixed
- name: Run MPI test examples
if: matrix.build-system == 'cmake' && matrix.compiler == 'MPI'
if: matrix.compiler == 'MPI'
run: |
mpirun -np 4 ./M2 --script ../../Macaulay2/packages/MPI/example-homotopies.m2
mpirun -np 4 ./M2 --script ../../Macaulay2/packages/MPI/example2.m2
Expand Down
16 changes: 8 additions & 8 deletions M2/Macaulay2/bin/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ void* testFunc(ArgCell* p);
int main(/* const */ int argc, /* const */ char *argv[], /* const */ char *env[])
{
#ifdef WITH_MPI
std::cout << "WITH_MPI defined" << std::endl;
// MPI preamble
if (getenv("OMPI_COMM_WORLD_RANK") != NULL) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);

// Initialize the MPI environment
if (MPI_Init(NULL, NULL) == MPI_SUCCESS) {
std::cout << "MPI_Init succeeded" << std::endl;
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
Expand All @@ -78,9 +77,10 @@ int main(/* const */ int argc, /* const */ char *argv[], /* const */ char *env[]
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

// Print off a hello world message
std::cout << "Hello world from process " << world_rank
<< " out of " << world_size << " processes" << std::endl;
}//end MPI preamble
//if (world_rank>0)
std::cout << "MPI: initialized process " << world_rank
<< " out of " << world_size << " processes" << std::endl;
}
#endif

/* find the number of environment variables defined */
Expand Down
14 changes: 9 additions & 5 deletions M2/Macaulay2/d/M2lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ int MPInumberOfProcesses() {

int MPImyProcessNumber() {
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
if (MPI_Comm_rank(MPI_COMM_WORLD, &world_rank) != MPI_SUCCESS)
world_rank = -1;
return world_rank;
}

Expand Down Expand Up @@ -112,10 +113,13 @@ void clean_up(void) {
#ifndef NDEBUG
trap();
#endif
#ifdef WITH_MPI
if (getenv("OMPI_COMM_WORLD_RANK") != NULL) {
printf("Bye world from process %d out of %d processes\n",
MPImyProcessNumber(), MPInumberOfProcesses());
#ifdef WITH_MPI
printf("MPI: about to finalize\n");
int n = MPImyProcessNumber();
if (n>=0) {
if (n>0)
printf("MPI: Bye world from process %d out of %d processes\n",
MPImyProcessNumber(), MPInumberOfProcesses());
MPI_Finalize();
}
#endif
Expand Down

0 comments on commit e01bbce

Please sign in to comment.