Example #1
0
bool FlagArg::setValue(ArgListType &argv)
{
   ArgListTypeIt onIt = find(argv, ArgType(OnFlag, false));
   ArgListTypeIt offIt = find(argv, ArgType(OffFlag, false));   
   bool foundOn = (onIt != argv.end());
   bool foundOff = (offIt != argv.end());
   // If both or neither are found, and there is no default behavior, bail
   if ((foundOn == foundOff) && !IsDeault) return false;
   if (foundOff) {
      // Mark it as accounted for
      offIt->second = true;
      Value = false;
   }
   if (foundOn) {
      // Mark it as accounted for
      onIt->second = true;
      Value = true; // On flag trumps off flag
   } else if (!foundOff) {
      Value = Deault; // If neither are found, use default
   }
   return true;
}
  KOKKOS_INLINE_FUNCTION ArgType team_scan( const ArgType & value , ArgType * const global_accum ) const
    {
    /*  // Make sure there is enough scratch space:
      typedef typename if_c< sizeof(ArgType) < TEAM_REDUCE_SIZE , ArgType , void >::type type ;

      volatile type * const work_value  = ((type*) m_exec.scratch_thread());

      *work_value = value ;

      memory_fence();

      if ( team_fan_in() ) {
        // The last thread to synchronize returns true, all other threads wait for team_fan_out()
        // m_team_base[0]                 == highest ranking team member
        // m_team_base[ m_team_size - 1 ] == lowest ranking team member
        //
        // 1) copy from lower to higher rank, initialize lowest rank to zero
        // 2) prefix sum from lowest to highest rank, skipping lowest rank

        type accum = 0 ;

        if ( global_accum ) {
          for ( int i = m_team_size ; i-- ; ) {
            type & val = *((type*) m_exec.pool_rev( m_team_base_rev + i )->scratch_thread());
            accum += val ;
          }
          accum = atomic_fetch_add( global_accum , accum );
        }

        for ( int i = m_team_size ; i-- ; ) {
          type & val = *((type*) m_exec.pool_rev( m_team_base_rev + i )->scratch_thread());
          const type offset = accum ;
          accum += val ;
          val = offset ;
        }

        memory_fence();
      }

      team_fan_out();

      return *work_value ;*/
      return ArgType();
    }
Example #3
0
void CommandLine::Process(ArgListType &argv, ostream & eout,
                          ostream & sout, const bool dolog)
{
   string s = " : ";
   if (find(argv, ArgType("-help", false)) != argv.end()) {
      DisplayHelp(eout);
      exit(0);
   }
   if (dolog)
      sout << "\n" << FuncName << " ";

   unsigned int i;
   for (i = 0; i < IntList.size(); i++) {
      if (IntList.at(i)->setValue(argv)) {
         if (dolog) sout << *(IntList.at(i)) << " ";
      } else {
         eout << "Error in " << FuncName << " : Unable to find required flag "
              << IntList.at(i)->getFlag() << "\n\n";
         DisplayHelp(eout);
         exit(EXIT_FAILURE);
      }
   }

   for (i = 0; i < DblList.size(); i++) {
      if (DblList.at(i)->setValue(argv)) {
         if (dolog) sout << *(DblList.at(i)) << " ";
      } else {
         eout << "Error in " << FuncName << " : Unable to find required flag "
              << DblList.at(i)->getFlag() << "\n\n";
         DisplayHelp(eout);
         exit(EXIT_FAILURE);
      }
   }

   for (i = 0; i < StrList.size(); i++) {
      if (StrList.at(i)->setValue(argv)) {
         if (dolog) sout << *(StrList.at(i)) << " ";
      } else {
         eout << "Error in " << FuncName << " : Unable to find required flag "
              << StrList.at(i)->getFlag() << "\n\n";
         DisplayHelp(eout);
         exit(EXIT_FAILURE);
      }
   }

   for (i = 0; i < FlagList.size(); i++) {
      if (FlagList.at(i)->setValue(argv)) {
         if (dolog) sout << *(FlagList.at(i)) << " ";
      } else {
         eout << "Error in " << FuncName << " : Unable to process flag "
              << FlagList.at(i)->getFlag() << endl;
         DisplayHelp(eout);
         exit(EXIT_FAILURE);
      }
   }

   for (i = 0; i < IntListList.size(); i++) {
      if (IntListList.at(i)->setValue(argv)) {
         if (dolog) sout << *(IntListList.at(i));
      } else {
         eout << "Error in " << FuncName << s << IntListList.at(i)->getErr() << endl;
         DisplayHelp(eout);
         exit(EXIT_FAILURE);
      }
   }

   for (i = 0; i < DblListList.size(); i++) {
      if (DblListList.at(i)->setValue(argv)) {
         if (dolog) sout << *(DblListList.at(i));
      } else {
         eout << "Error in " << FuncName << s << DblListList.at(i)->getErr() << endl;
         DisplayHelp(eout);
         exit(EXIT_FAILURE);
      }
   }

   for (i = 0; i < StrListList.size(); i++) {
      if (StrListList.at(i)->setValue(argv)) {
         if (dolog) sout << *(StrListList.at(i));
      } else {
         eout << "Error in " << FuncName << s << StrListList.at(i)->getErr() << endl;
         DisplayHelp(eout);
         exit(EXIT_FAILURE);
      }
   }

   if (dolog)
      sout << "\n\n";

   for (ArgListTypeIt it = argv.begin(); it != argv.end(); it++) {
      // If not accounted for
      if (!it->second) {
         eout << "Error in " << FuncName << " : flag " << it->first
              << " not recognized." << endl;
         DisplayHelp(eout);
         exit(EXIT_FAILURE);
      }
   }
   return;
}