tonyyxliu / CUHKSZ-CSC4005

Project Materials for CUHK(SZ) Course CSC4005: Parallel Programming
MIT License
79 stars 31 forks source link

Problem using MPI_Gather with Booleans #50

Closed 0x727AA7D closed 1 year ago

0x727AA7D commented 1 year ago

I'm trying to gather bools from processes.

I wrote MPI_Gather(&localSorted, 1, MPI_CXX_BOOL, &localSorteds, 1, MPI_CXX_BOOL, MASTER, MPI_COMM_WORLD);, where localSorteds = (bool*)malloc(numtasks*sizeof(bool)) and localSorted is simply a bool in each process.

However, it seems that MPI_Gather just messed up localSorteds. For example, before MPI_Gather I have task0:false and task1:false, but after Gather, localSorteds[0] can sometimes become true. What might lead to this problem? Is there any possible fix?

0x727AA7D commented 1 year ago

The problem is solved... Sorry, I figured out I wrote an extra & before the pointer. Guess I need to read more CPP book ;(