Featured post
c - inter processes shared memory and pthread_barrier: how to be safe? -
i wanted simple solution inter processes barrier. here solution: solution
but totally lost mmap... first try, fails 1 out of ten times (segfault or deadlock).
i understand problem comes synchronization issue, can't find it. found example set mmaped memory (example), not sure mmaped pthread_barrier.
here extract of code:
#define mmap_file "/tmp/mmapped_bigdft.bin" void init_barrier() { pthread_barrier_t *shared_mem_barrier; pthread_barrierattr_t barattr; pthread_barrierattr_setpshared(&barattr, pthread_process_shared); hbcast_fd = open(mmap_file, o_rdwr | o_creat | o_trunc, (mode_t)0600); result = lseek(hbcast_fd, sizeof(pthread_barrier_t)-1, seek_set); result = write(hbcast_fd, "", 1); shared_mem_barrier = (pthread_barrier_t*) mmap(0, sizeof(pthread_barrier_t), prot_read | prot_write, map_shared, hbcast_fd, 0); if (mpi_rank == 0) { int err = pthread_barrier_init(shared_mem_barrier, &barattr, host_size); } mpi_barrier(some_communicator); }
questions:
- do miss in mmap initialization?
- which operation should performed processes, , should one?
new question
which safier managing pthread barrier? or based on same mechanism?
- shmget
- shm_open
- mmap
- another one
as charles has mentioned, looks truncation what's getting you. also, should initialise attributes using pthread_barrierattr_init.
as other question, 1 process should initialisation, , processes should call pthread_barrier_wait (just mpi).
i saw other question, know why don't want use mpi. you'd single mpi barrier initialise pthread barriers, so:
if (rank == 0) { /* create shared memory segment, initialise barrier. */ } mpi_barrier(communicator); if (rank != 0) { /* load shared memory segment, cast pthread_barrier_t* , store. * it's initialised */ }
- Get link
- X
- Other Apps
Comments
Post a Comment