00001 #include "converse.h" 00002 00003 //#define PERFORM_DEBUG 1 00004 #if PERFORM_DEBUG 00005 #define DEBUG(a) do { a } while(false) 00006 #else 00007 #define DEBUG(a) 00008 #endif 00009 00010 #if CMK_HAS_CXX11_ATOMIC 00011 #include <atomic> 00012 #elif CMK_HAS_CXX0X_CSTDATOMIC 00013 #include <cstdatomic> 00014 #else 00015 #error "Configure should have errored on missing C++11 atomic library support" 00016 #endif 00017 00018 #if CMK_USE_LRTS 00019 extern void LrtsDrainResources(); 00020 #else 00021 void LrtsDrainResources() { } 00022 #endif 00023 00024 static std::atomic<int> interopCommThdExit{0}; 00025 std::atomic<int> _cleanUp{0}; 00026 00027 CpvCExtern(int,interopExitFlag); 00028 00029 #if CMK_USE_LRTS 00030 extern void CommunicationServerThread(int sleepTime); 00031 #else 00032 void CommunicationServerThread(int sleepTime) { } 00033 #endif 00034 00035 extern int CharmLibInterOperate; 00036 00037 void StartInteropScheduler() { 00038 DEBUG(printf("[%d]Starting scheduler [%d]/[%d]\n",CmiMyPe(),CmiMyRank(),CmiMyNodeSize());); 00039 if (CmiMyRank() == CmiMyNodeSize()) { 00040 while (interopCommThdExit.load(std::memory_order_relaxed) != CmiMyNodeSize()) 00041 { 00042 CommunicationServerThread(5); 00043 } 00044 DEBUG(printf("[%d] Commthread Exit Scheduler\n",CmiMyPe());); 00045 LrtsDrainResources(); 00046 interopCommThdExit = 0; 00047 } else { 00048 CsdScheduler(-1); 00049 } 00050 CmiNodeAllBarrier(); 00051 } 00052 00053 void StopInteropScheduler() { 00054 DEBUG(printf("[%d] Exit Scheduler\n",CmiMyPe());); 00055 CpvAccess(interopExitFlag) = 1; 00056 interopCommThdExit++; 00057 }