Hi
I am trying to scatter some values to workers and then gather them. But I get strange error in gather step.
Any suggestions?

Below is the code and error file.

//mpicxx test-boost.cpp -o test-boost -I /home1/mutlu/boost/include/boost-1_37/ /home1/mutlu/boost/lib/libboost_mpi-gcc41-mt-1_37.a

#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/mpi/collectives.hpp>
#include <boost/thread/mutex.hpp>
#include <iostream>
#include <vector>

#define MASTER 0

namespace mpi = boost::mpi;
using namespace std;

struct x{
string name;
int age;
};

int arraySize = 23;

void silly_func(int *px, int sz){
for(int i = 0; i < sz; i++)
px[i] = 100;
}

int main(int argc, char* argv[]) 
{
mpi::environment env(argc, argv);
mpi::communicator world;
int m_mySize, w_mySize, kk,i;
int *myValues;
vector<int> a;
vector<int> aa;
  
for(int i = 0; i < arraySize; i++) a.push_back(i);  
w_mySize = arraySize / world.size();
if (world.rank() == MASTER){  
   m_mySize = arraySize / world.size() + arraySize % world.size();
myValues = (int *) malloc(m_mySize);
}
   else{
  
myValues = (int *) malloc(w_mySize);
   }
  
   if (world.rank() == MASTER)
   scatter(world, a, myValues, w_mySize, 0);
   else
   scatter(world, a, myValues, w_mySize, 0);
  

if (world.rank() == MASTER) // append the remaining elements
{
   for (i = w_mySize * world.size(), kk = 0; i < arraySize; i++, kk++)
   myValues[w_mySize + kk] = a[w_mySize * world.size() + kk];
}
  
   cout << "my rank is " << world.rank() << " and my values are" << endl; 
   if (world.rank() == MASTER)
   for (int i = 0; i < m_mySize; i++)
   cout << myValues[i] << endl; 
   if (world.rank() != MASTER)
   for (int i = 0; i < w_mySize; i++)
   cout << myValues[i] << endl; 
if (world.rank() != MASTER)
silly_func(myValues, w_mySize);
else
   silly_func(myValues, m_mySize);   
 
   if (world.rank() == MASTER)
   gather(world, myValues, m_mySize, aa, 0);
else
gather(world, myValues, w_mySize, aa, 0);
if (world.rank() == MASTER){
cout << "======================="<< endl;
for(int i = 0; i < aa.size(); i++)
cout << aa[i] << endl;
}
  
  
}

and error file is

[ceng3:23784] *** Process received signal ***
[ceng3:23784] Signal: Segmentation fault (11)
[ceng3:23784] Signal code: Address not mapped (1)
[ceng3:23784] Failing at address: (nil)
[ceng3:23784] [ 0] /lib64/libpthread.so.0 [0x30e100de80]
[ceng3:23784] [ 1] /lib64/libc.so.6(memcpy+0x37) [0x30e047a107]
[ceng3:23784] [ 2] /usr/mpi/gcc/openmpi-1.2.8/lib64/libmpi.so.0(ompi_ddt_copy_content_same_ddt+0xe8) [0x2b180e3b5618]
[ceng3:23784] [ 3] /usr/mpi/gcc/openmpi-1.2.8/lib64/libmpi.so.0(ompi_ddt_sndrcv+0x3f3) [0x2b180e3b3ef3]
[ceng3:23784] [ 4] /usr/mpi/gcc/openmpi-1.2.8/lib64/openmpi/mca_coll_basic.so(mca_coll_basic_gather_intra+0xd2) [0x2b18142f20a2]
[ceng3:23784] [ 5] /usr/mpi/gcc/openmpi-1.2.8/lib64/libmpi.so.0(PMPI_Gather+0x19b) [0x2b180e3c7ccb]
[ceng3:23784] [ 6] test-boost(_ZN5boost3mpi6detail11gather_implIiEEvRKNS0_12communicatorEPKT_iPS6_iN4mpl_5bool_ILb1EEE+0x6b) [0x414b29]
[ceng3:23784] [ 7] test-boost(_ZN5boost3mpi6gatherIiEEvRKNS0_12communicatorEPKT_iPS5_i+0x50) [0x414c82]
[ceng3:23784] [ 8] test-boost(_ZN5boost3mpi6gatherIiEEvRKNS0_12communicatorEPKT_iRSt6vectorIS5_SaIS5_EEi+0x42) [0x414ce8]
[ceng3:23784] [ 9] test-boost(main+0x342) [0x40f62c]
[ceng3:23784] [10] /lib64/libc.so.6(__libc_start_main+0xf4) [0x30e041d8b4]
[ceng3:23784] [11] test-boost(__gxx_personality_v0+0x141) [0x40f199]
[ceng3:23784] *** End of error message ***
mpirun noticed that job rank 0 with PID 23784 on node ceng3-ib exited on signal 11 (Segmentation fault).