Project

General

Profile

Bug #1577

User-level thread based OpenMP integration support on Mac

Added by Seonmyeong Bak 6 months ago. Updated 23 days ago.

Status:
Closed
Priority:
Normal
Category:
-
Target version:
-
Start date:
06/14/2017
Due date:
% Done:

100%


Description

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.


Subtasks

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

History

#1 Updated by Seonmyeong Bak 6 months ago

  • Status changed from New to Implemented

The change to resolve this issue is included in this patch.
https://charm.cs.illinois.edu/gerrit/#/c/2427/

#2 Updated by Seonmyeong Bak 5 months 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.

#ifndef _STRUCT_MCONTEXT64
#if __DARWIN_UNIX03
#define _STRUCT_MCONTEXT64 struct __darwin_mcontext64
_STRUCT_MCONTEXT64 {
_STRUCT_X86_EXCEPTION_STATE64 __es;
_STRUCT_X86_THREAD_STATE64 __ss;
_STRUCT_X86_FLOAT_STATE64 __fs;
};

#define _STRUCT_MCONTEXT_AVX64 struct __darwin_mcontext_avx64
_STRUCT_MCONTEXT_AVX64 {
_STRUCT_X86_EXCEPTION_STATE64 __es;
_STRUCT_X86_THREAD_STATE64 __ss;
_STRUCT_X86_AVX_STATE64 __fs;
};

#else /* !__DARWIN_UNIX03 */
#define _STRUCT_MCONTEXT64 struct mcontext64
_STRUCT_MCONTEXT64 {
_STRUCT_X86_EXCEPTION_STATE64 es;
_STRUCT_X86_THREAD_STATE64 ss;
_STRUCT_X86_FLOAT_STATE64 fs;
};

#define _STRUCT_MCONTEXT_AVX64 struct mcontext_avx64
_STRUCT_MCONTEXT_AVX64 {
_STRUCT_X86_EXCEPTION_STATE64 es;
_STRUCT_X86_THREAD_STATE64 ss;
_STRUCT_X86_AVX_STATE64 fs;
};

#endif /* __DARWIN_UNIX03 /
#endif /
_STRUCT_MCONTEXT64 */

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

#endif /* _I386_MCONTEXT_H */

#ifndef STRUCT_UCONTEXT
#if __DARWIN_UNIX03
#define _STRUCT_UCONTEXT struct __darwin_ucontext
#else /* !
_DARWIN_UNIX03 /
#define _STRUCT_UCONTEXT struct ucontext
#endif /
__DARWIN_UNIX03 */
_STRUCT_UCONTEXT {
int uc_onstack;
__darwin_sigset_t uc_sigmask; /* signal mask used by this context /
_STRUCT_SIGALTSTACK uc_stack; /
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 /
#ifdef _XOPEN_SOURCE
_STRUCT_MCONTEXT __mcontext_data;
#endif /
_XOPEN_SOURCE */
};

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

#endif /* _STRUCT_UCONTEXT */
~

#3 Updated by Seonmyeong Bak 4 months ago

  • Status changed from New to Implemented

#4 Updated by Seonmyeong Bak 23 days ago

  • Status changed from Implemented to Closed

Also available in: Atom PDF