Bug #1577

User-level thread based OpenMP integration support on Mac

Added by Seonmyeong Bak about 2 years ago. Updated over 1 year ago.

Target version:
Start date:
Due date:
% Done:



OpenMP integration can work with GCC, ICC and Clang, which are OpenMP enabled.

Apple Clang, the default compiler on Mac, doesn't have OpenMP feature. So, this integration cannot be used on Mac.
Until now, open source clang and gcc(installed from Homebrew) are tested.
Open source clang has some issues for dependent packages on Charm++. So, Charm++ is not built with the version of Clang. (Maybe, Darwin module owner knows how to fix this)
Open source gcc is OK to build Charm++ and OpenMP integration but the OpenMP integration is not linked to charm++ application.

So, first this issue will support the open source gcc and then support the open source clang.


Feature #1609: User-level thread implementation based on Boost context libraryMergedSeonmyeong Bak


#1 Updated by Seonmyeong Bak about 2 years ago

  • Status changed from New to Implemented

The change to resolve this issue is included in this patch.

#2 Updated by Seonmyeong Bak about 2 years ago

  • Status changed from Implemented to New
  • Subject changed from OpenMP integration support on Mac to User-level thread based OpenMP integration support on Mac

The initial issue mentioned above is resolved. But the ULT based OpenMP integration doesn't work because of the different behavior of 'setjmp/longjmp' and 'ucontext_t' routines.

The following is the ucontext.h in Linux.
It stores stack pointer(rsp), base pointer(rbp), instruction pointer(rip) and destination index(rdi) as following
struct _libc_fpstate {
/* 64-bit FXSAVE format. */
__uint16_t cwd;
__uint16_t swd;
__uint16_t ftw;
__uint16_t fop;
__uint64_t rip;
__uint64_t rdp;
__uint32_t mxcsr;
__uint32_t mxcr_mask;
struct _libc_fpxreg _st8;
struct _libc_xmmreg _xmm16;
__uint32_t padding24;

/* Structure to describe FPU registers. */
typedef struct _libc_fpstate *fpregset_t;

/* Context to describe whole processor state. */
typedef struct {
gregset_t gregs;
/* Note that fpregs is a pointer. */
fpregset_t fpregs;
extension unsigned long long __reserved1 [8];
} mcontext_t;

/* Userlevel context. */
typedef struct ucontext {
unsigned long int uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext;
__sigset_t uc_sigmask;
struct _libc_fpstate __fpregs_mem;
} ucontext_t;

However in MacOSX, the implementation of ucontext_t is different.
As you can see, the number of fields in mcontext_t is much lesser than that of linux version. MacOSX version doesn't store the whole state of processor so that the context switching across threads cannot be guaranteed.

#define _STRUCT_MCONTEXT64 struct __darwin_mcontext64

#define _STRUCT_MCONTEXT_AVX64 struct __darwin_mcontext_avx64

#else /* !__DARWIN_UNIX03 */
#define _STRUCT_MCONTEXT64 struct mcontext64

#define _STRUCT_MCONTEXT_AVX64 struct mcontext_avx64

#endif /* __DARWIN_UNIX03 /
#endif /

#ifndef _MCONTEXT_T
#define _MCONTEXT_T
#if defined(LP64)
typedef _STRUCT_MCONTEXT64 mcontext_t;
typedef _STRUCT_MCONTEXT32 *mcontext_t;
#endif /

#endif /* _I386_MCONTEXT_H */

#define _STRUCT_UCONTEXT struct __darwin_ucontext
#else /* !
#define _STRUCT_UCONTEXT struct ucontext
#endif /
int uc_onstack;
__darwin_sigset_t uc_sigmask; /* signal mask used by this context /
stack used by this context /
_STRUCT_UCONTEXT *uc_link; /
pointer to resuming context /
__darwin_size_t uc_mcsize; /
size of the machine context passed in /
_STRUCT_MCONTEXT *uc_mcontext; /
pointer to machine specific context /
_STRUCT_MCONTEXT __mcontext_data;
#endif /

/* user context /
typedef _STRUCT_UCONTEXT ucontext_t; /
[???] user context */

#endif /* _STRUCT_UCONTEXT */

#3 Updated by Seonmyeong Bak almost 2 years ago

  • Status changed from New to Implemented

#4 Updated by Seonmyeong Bak over 1 year ago

  • Status changed from Implemented to Closed

Also available in: Atom PDF