예제 #1
0
void Set_Floating_Point_Exception_Handling(const bool enable,const bool division_by_zero,const bool invalid_operation,const bool overflow,const bool underflow,const bool inexact_result)
{
    static bool have_original_action=false;
    static struct sigaction original_action;
    if(!have_original_action){ // initialize with original action
        sigaction(SIGFPE,0,&original_action);}
    if(enable){
        int exceptions=0;
        if(division_by_zero) exceptions|=FE_DIVBYZERO;
        if(invalid_operation) exceptions|=FE_INVALID;
        if(overflow) exceptions|=FE_OVERFLOW;
        if(underflow) exceptions|=FE_UNDERFLOW;
        if(inexact_result) exceptions|=FE_INEXACT;
        // avoid catching delayed exceptions caused by external code
        fedisableexcept(FE_ALL_EXCEPT);
        feclearexcept(exceptions);
        // install new handler
        struct sigaction action;
        action.sa_flags=SA_SIGINFO;
        action.sa_sigaction=Floating_Point_Exception_Handler;
        sigemptyset(&action.sa_mask);
        if(sigaction(SIGFPE,&action,0)) PHYSBAM_FATAL_ERROR("Could not register FPE signal handler");
        feenableexcept(exceptions);}
    else{
        if(sigaction(SIGFPE,&original_action,0)) PHYSBAM_FATAL_ERROR("Could not restore FPE signal handler");
        fedisableexcept(FE_ALL_EXCEPT);}
}
/**
@details
-# If incoming on_off flag is true assign fpe_sig_handler() as the signal handler for SIGFPE.
-# Else revert to the default signal handler SIG_DFL.
-# set trap_sigfpe to the current on_off status
   Requirement [@ref r_exec_signal_0].
   Requirement [@ref r_exec_signal_0].
*/
int Trick::Executive::set_trap_sigfpe(bool on_off) {
    static struct sigaction sigact;

    if ( on_off ) {
        /* Assign fpe_sig_handler() as the signal handler for SIGFPE. */
#ifdef __linux
        feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW);
#endif
#if (__APPLE__ | __CYGWIN__ | __INTERIX )
        sigact.sa_handler = (void (*)(int)) fpe_sig_handler;
#else
        sigact.sa_flags = SA_SIGINFO;
        sigact.sa_sigaction = (void (*)(int, siginfo_t *, void *)) fpe_sig_handler;
#endif
    } else {
#ifdef __linux
        fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW);
#endif
        sigact.sa_handler = SIG_DFL;
    }

    if (sigaction(SIGFPE, &sigact, NULL) < 0) {
        perror("sigaction() failed for SIGFPE");
    } else {
        trap_sigfpe = on_off ;
    }

    return(0) ;
}
예제 #3
0
static void
test_feupdateenv (void)
{
#if defined FE_NOMASK_ENV && defined FE_ALL_EXCEPT
  int res;

  fedisableexcept (FE_ALL_EXCEPT);

  res = feupdateenv (FE_NOMASK_ENV);

  if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) && (res != 0))
    {
      puts ("feupdateenv (FE_NOMASK_ENV)) not supported, cannot test.");
      return;
    }
  else if (res != 0)
    {
      puts ("feupdateenv (FE_NOMASK_ENV) failed");
      count_errors++;
    }

  if (fegetexcept () != FE_ALL_EXCEPT)
    {
      puts ("feupdateenv did not set all exceptions");
      count_errors++;
    }
#endif
}
예제 #4
0
파일: init.c 프로젝트: Exteris/Gerris
/**
 * gfs_catch_floating_point_exceptions:
 *
 * Catch the default floating-point exceptions set in the Gerris
 * library.
 */
void gfs_catch_floating_point_exceptions (void)
{
#ifdef EXCEPTIONS
  fedisableexcept (EXCEPTIONS);
  feclearexcept (EXCEPTIONS);
#endif /* EXCEPTIONS */
}
예제 #5
0
파일: init.c 프로젝트: Exteris/Gerris
/**
 * gfs_disable_floating_point_exceptions:
 *
 * Disables floating-point exceptions (they are enabled by default
 * when using the Gerris library).
 */
void gfs_disable_floating_point_exceptions (void)
{
#ifdef EXCEPTIONS
  disabled_fpe = TRUE;
  fedisableexcept (EXCEPTIONS);
#endif /* !EXCEPTIONS */
}
예제 #6
0
int fpe_disable_traps (const int excepts) {
#ifdef FPE_WITH_TRAP_CONTROL
   return fedisableexcept (excepts);
   fpe_handler_update_mask ();
#else
   return -1;
#endif
}
예제 #7
0
파일: test-fenv.c 프로젝트: alucas/glibc
/* Test that program aborts with no masked interrupts */
static void
feexcp_nomask_test (const char *flag_name, int fe_exc)
{
  int status;
  pid_t pid;

  if (!EXCEPTION_ENABLE_SUPPORTED (fe_exc) && feenableexcept (fe_exc) == -1)
    {
      printf ("Test: not testing feenableexcept, it isn't implemented.\n");
      return;
    }

  printf ("Test: after feenableexcept (%s) processes will abort\n",
	  flag_name);
  printf ("      when feraiseexcept (%s) is called.\n", flag_name);
  pid = fork ();
  if (pid == 0)
    {
#ifdef RLIMIT_CORE
      /* Try to avoid dumping core.  */
      struct rlimit core_limit;
      core_limit.rlim_cur = 0;
      core_limit.rlim_max = 0;
      setrlimit (RLIMIT_CORE, &core_limit);
#endif

      fedisableexcept (FE_ALL_EXCEPT);
      feenableexcept (fe_exc);
      feraiseexcept (fe_exc);
      exit (2);
    }
  else if (pid < 0)
    {
      if (errno != ENOSYS)
	{
	  printf ("  Fail: Could not fork.\n");
	  ++count_errors;
	}
      else
	printf ("  `fork' not implemented, test ignored.\n");
    }
  else {
    if (waitpid (pid, &status, 0) != pid)
      {
	printf ("  Fail: waitpid call failed.\n");
	++count_errors;
      }
    else if (WIFSIGNALED (status) && WTERMSIG (status) == SIGFPE)
      printf ("  Pass: Process received SIGFPE.\n");
    else
      {
	printf ("  Fail: Process didn't receive signal and exited with status %d.\n",
		status);
	++count_errors;
      }
  }
}
예제 #8
0
int clear_fpe_x87_sse_(void)
{
  int retcode;

  retcode = feclearexcept(FE_ALL_EXCEPT);
  retcode = fedisableexcept(FE_ALL_EXCEPT);

  return(retcode);
}
예제 #9
0
파일: fenv_test.cpp 프로젝트: MIPS/bionic
TEST(fenv, fedisableexcept_fegetexcept) {
  feclearexcept(FE_ALL_EXCEPT);
  ASSERT_EQ(0, fetestexcept(FE_ALL_EXCEPT));

  // No SIGFPE please...
  ASSERT_EQ(0, fedisableexcept(FE_ALL_EXCEPT));
  ASSERT_EQ(0, fegetexcept());
  ASSERT_EQ(0, feraiseexcept(FE_INVALID));
  ASSERT_EQ(FE_INVALID, fetestexcept(FE_ALL_EXCEPT));
}
예제 #10
0
파일: uninit.c 프로젝트: CansenJIANG/igraph
 static void
  ieee0(Void)
        
{
    /* Clear all exception flags */
    if (fedisableexcept(FE_ALL_EXCEPT)==-1)
         unsupported_error();
    if (feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW)==-1)
         unsupported_error();
}
예제 #11
0
void enableFloatingPointTraps(bool enable)
{
	static const int FLAGS = FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW;
	if(enable)
	{
			feenableexcept(FLAGS);
	}
	else
	{
			fedisableexcept(FLAGS);
	}
}
예제 #12
0
int 
main(int argc, char **argv)
{

    //int x = _FPU_DEFAULT & ~(_FPU_MASK_ZM | _FPU_MASK_IM);
    //_FPU_SETCW(x);

    int result = fedisableexcept(FE_ALL_EXCEPT);
    printf("%d\n", result);

    int i = -1 / 0;
}
예제 #13
0
void MPQCInit::init_fp() {
#ifdef HAVE_FEENABLEEXCEPT
// this uses a glibc extension to trap on individual exceptions
#ifdef FE_DIVBYZERO
  feenableexcept(FE_DIVBYZERO);
#endif
#ifdef FE_INVALID
  feenableexcept(FE_INVALID);
#endif
#ifdef FE_OVERFLOW
  feenableexcept(FE_OVERFLOW);
#endif
#endif

#ifdef HAVE_FEDISABLEEXCEPT
// this uses a glibc extension to not trap on individual exceptions
#ifdef FE_UNDERFLOW
  fedisableexcept(FE_UNDERFLOW);
#endif
#ifdef FE_INEXACT
  fedisableexcept(FE_INEXACT);
#endif
#endif
}
예제 #14
0
파일: libmesh.C 프로젝트: dschwen/libmesh
/**
 * Toggle floating point exceptions -- courtesy of Cody Permann & MOOSE team
 */
void enableFPE(bool on)
{
#if !defined(LIBMESH_HAVE_FEENABLEEXCEPT) && defined(LIBMESH_HAVE_XMMINTRIN_H) && !defined(__SUNPRO_CC)
  static int flags = 0;
#endif

  if (on)
    {
#ifdef LIBMESH_HAVE_FEENABLEEXCEPT
      feenableexcept(FE_DIVBYZERO | FE_INVALID);
#elif  LIBMESH_HAVE_XMMINTRIN_H
#  ifndef __SUNPRO_CC
      flags = _MM_GET_EXCEPTION_MASK();           // store the flags
      _MM_SET_EXCEPTION_MASK(flags & ~_MM_MASK_INVALID);
#  endif
#endif

#if LIBMESH_HAVE_DECL_SIGACTION
      struct sigaction new_action, old_action;

      // Set up the structure to specify the new action.
      new_action.sa_sigaction = libmesh_handleFPE;
      sigemptyset (&new_action.sa_mask);
      new_action.sa_flags = SA_SIGINFO;

      sigaction (SIGFPE, nullptr, &old_action);
      if (old_action.sa_handler != SIG_IGN)
        sigaction (SIGFPE, &new_action, nullptr);
#endif
    }
  else
    {
#ifdef LIBMESH_HAVE_FEDISABLEEXCEPT
      fedisableexcept(FE_DIVBYZERO | FE_INVALID);
#elif  LIBMESH_HAVE_XMMINTRIN_H
#  ifndef __SUNPRO_CC
      _MM_SET_EXCEPTION_MASK(flags);
#  endif
#endif
      signal(SIGFPE, SIG_DFL);
    }
}
예제 #15
0
bool disableFPExceptions() {
	bool exceptionsWereEnabled = false;
#if defined(WIN32)
	_clearfp();
	uint32_t cw = _controlfp(0, 0);
	exceptionsWereEnabled = ~cw & (_EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW);
	cw |= _EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW;
	_controlfp(cw, _MCW_EM);
#elif defined(__OSX__)
#if !defined(MTS_SSE)
#warning SSE must be enabled to handle FP exceptions on OSX
#else
	exceptionsWereEnabled = query_fpexcept_sse() != 0;
#endif
#else
	exceptionsWereEnabled = 
		fegetexcept() & (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
	fedisableexcept(FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
#endif
#if defined(MTS_SSE)
	disable_fpexcept_sse();
#endif
	return exceptionsWereEnabled;
}
예제 #16
0
	int fpe_disable_trap( unsigned int except )
	{
		return fedisableexcept( (int)except );
	}
예제 #17
0
파일: nan.c 프로젝트: glycerine/lush2
static int setup_fpu(int doINV, int doOFL)
{
   
#if defined(WIN32)
   
  /* Win32 uses _controlfp() */
   
   unsigned int mask = _controlfp(0,0);
   fpe_inv = doINV;
   fpe_ofl = doOFL;
   if (doINV) mask&=(~_EM_INVALID); else mask|=(_EM_INVALID);
   if (doOFL) mask&=(~_EM_OVERFLOW); else mask|=(_EM_OVERFLOW);
   if (doOFL) mask&=(~_EM_ZERODIVIDE); else mask|=(_EM_ZERODIVIDE);
   _controlfp(mask, _MCW_EM);
   return 1;

#elif defined(HAVE_FPSETMASK)

   /* SysVr4 defines fpsetmask() */
   
   int mask = 0;
   fpe_inv = doINV;
   fpe_ofl = doOFL;
#ifdef FP_X_INV
   if (doINV) mask |= FP_X_INV;
#endif
#ifdef FP_X_OFL
   if (doOFL) mask |= FP_X_OFL;
#endif
#ifdef FP_X_DZ
   if (doOFL) mask |= FP_X_DZ;
#endif
   fpsetmask( mask );
   return 1;
  
#elif defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT)

   /* GLIBC-2.2 model */
   
   int mask1 = 0;
   int mask2 = 0;
   fpe_inv = doINV;
   fpe_ofl = doOFL;

#ifdef FE_INVALID
   if (doINV) 
      mask1 |= FE_INVALID;
   else
      mask2 |= FE_INVALID;    
#endif
#ifdef FE_DIVBYZERO
   if (doOFL) 
      mask1 |= FE_DIVBYZERO;
   else
      mask2 |= FE_DIVBYZERO;    
#endif
#ifdef FE_OVERFLOW
   if (doOFL) 
      mask1 |= FE_OVERFLOW;
   else
      mask2 |= FE_OVERFLOW;    
#endif
   feenableexcept(mask1);
   fedisableexcept(mask2);
   return 1;

#elif defined(HAVE_FPU_CONTROL_H)

   /* Older GLIBC */
  
   int mask = 0;
   fpe_inv = doINV;
   fpe_ofl = doOFL;
   
#ifdef _FPU_DEFAULT
   mask = _FPU_DEFAULT;
#endif
  
#define DO(c,f) mask=((c)?(mask|(f)):(mask&~(f)));

#if defined(__i386__) || defined(__alpha__)
#ifdef _FPU_MASK_IM
   DO(!doINV, _FPU_MASK_IM);
#endif
#ifdef _FPU_MASK_OM
   DO(!doOFL, _FPU_MASK_OM);
#endif
#ifdef _FPU_MASK_ZM
   DO(!doOFL, _FPU_MASK_ZM);
#endif
#else
#ifdef _FPU_MASK_IM
   DO(doINV, _FPU_MASK_IM);
#endif
#ifdef _FPU_MASK_OM
   DO(doOFL, _FPU_MASK_OM);
#endif
#ifdef _FPU_MASK_ZM
   DO(doOFL, _FPU_MASK_ZM);
#endif
#ifdef _FPU_MASK_V
   DO(doINV, _FPU_MASK_V);
#endif
#ifdef _FPU_MASK_O
   DO(doOFL, _FPU_MASK_O);
#endif
#ifdef _FPU_MASK_Z
   DO(doOFL, _FPU_MASK_Z);
#endif
#ifdef _FPU_MASK_OPERR
   DO(doINV, _FPU_MASK_OPERR);
#endif
#ifdef _FPU_MASK_OVFL
   DO(doOFL, _FPU_MASK_OPERR);
#endif
#ifdef _FPU_MASK_DZ
   DO(doOFL, _FPU_MASK_DZ);
#endif
#endif
  /* continue */
#if defined(HAVE___SETFPUCW)
   __setfpucw( mask );
   return 1;
#elif defined(_FPU_SETCW)
   _FPU_SETCW( mask );
   return 1;
#undef DO
#endif

#endif
   
   /* Default */
   return 0;
}
예제 #18
0
// Call scotch with options from dictionary.
Foam::label Foam::scotchDecomp::decompose
(
    const List<int>& adjncy,
    const List<int>& xadj,
    const scalarField& cWeights,

    List<int>& finalDecomp
)
{
    // Dump graph
    if (decompositionDict_.found("scotchCoeffs"))
    {
        const dictionary& scotchCoeffs =
            decompositionDict_.subDict("scotchCoeffs");

        if (scotchCoeffs.found("writeGraph"))
        {
            Switch writeGraph(scotchCoeffs.lookup("writeGraph"));

            if (writeGraph)
            {
                OFstream str(mesh_.time().path() / mesh_.name() + ".grf");

                Info<< "Dumping Scotch graph file to " << str.name() << endl
                    << "Use this in combination with gpart." << endl;

                label version = 0;
                str << version << nl;
                // Numer of vertices
                str << xadj.size()-1 << ' ' << adjncy.size() << nl;
                // Numbering starts from 0
                label baseval = 0;
                // Has weights?
                label hasEdgeWeights = 0;
                label hasVertexWeights = 0;
                label numericflag = 10*hasEdgeWeights+hasVertexWeights;
                str << baseval << ' ' << numericflag << nl;
                for (label cellI = 0; cellI < xadj.size()-1; cellI++)
                {
                    label start = xadj[cellI];
                    label end = xadj[cellI+1];
                    str << end-start;

                    for (label i = start; i < end; i++)
                    {
                        str << ' ' << adjncy[i];
                    }
                    str << nl;
                }
            }
        }
    }


    // Strategy
    // ~~~~~~~~

    // Default.
    SCOTCH_Strat stradat;
    check(SCOTCH_stratInit(&stradat), "SCOTCH_stratInit");

    if (decompositionDict_.found("scotchCoeffs"))
    {
        const dictionary& scotchCoeffs =
            decompositionDict_.subDict("scotchCoeffs");


        string strategy;
        if (scotchCoeffs.readIfPresent("strategy", strategy))
        {
            if (debug)
            {
                Info<< "scotchDecomp : Using strategy " << strategy << endl;
            }
            SCOTCH_stratGraphMap(&stradat, strategy.c_str());
            //fprintf(stdout, "S\tStrat=");
            //SCOTCH_stratSave(&stradat, stdout);
            //fprintf(stdout, "\n");
        }
    }


    // Graph
    // ~~~~~

    List<int> velotab;


    // Check for externally provided cellweights and if so initialise weights
    scalar minWeights = gMin(cWeights);
    if (cWeights.size() > 0)
    {
        if (minWeights <= 0)
        {
            WarningIn
            (
                "scotchDecomp::decompose"
                "(const pointField&, const scalarField&)"
            )   << "Illegal minimum weight " << minWeights
                << endl;
        }

        if (cWeights.size() != xadj.size()-1)
        {
            FatalErrorIn
            (
                "scotchDecomp::decompose"
                "(const pointField&, const scalarField&)"
            )   << "Number of cell weights " << cWeights.size()
                << " does not equal number of cells " << xadj.size()-1
                << exit(FatalError);
        }

        // Convert to integers.
        velotab.setSize(cWeights.size());
        forAll(velotab, i)
        {
            velotab[i] = int(cWeights[i]/minWeights);
        }
    }



    SCOTCH_Graph grafdat;
    check(SCOTCH_graphInit(&grafdat), "SCOTCH_graphInit");
    check
    (
        SCOTCH_graphBuild
        (
            &grafdat,
            0,                      // baseval, c-style numbering
            xadj.size()-1,          // vertnbr, nCells
            xadj.begin(),           // verttab, start index per cell into adjncy
            &xadj[1],               // vendtab, end index  ,,
            velotab.begin(),        // velotab, vertex weights
            NULL,                   // vlbltab
            adjncy.size(),          // edgenbr, number of arcs
            adjncy.begin(),         // edgetab
            NULL                    // edlotab, edge weights
        ),
        "SCOTCH_graphBuild"
    );
    check(SCOTCH_graphCheck(&grafdat), "SCOTCH_graphCheck");


    // Architecture
    // ~~~~~~~~~~~~
    // (fully connected network topology since using switch)

    SCOTCH_Arch archdat;
    check(SCOTCH_archInit(&archdat), "SCOTCH_archInit");

    List<label> processorWeights;
    if (decompositionDict_.found("scotchCoeffs"))
    {
        const dictionary& scotchCoeffs =
            decompositionDict_.subDict("scotchCoeffs");

        scotchCoeffs.readIfPresent("processorWeights", processorWeights);
    }
    if (processorWeights.size())
    {
        if (debug)
        {
            Info<< "scotchDecomp : Using procesor weights " << processorWeights
                << endl;
        }
        check
        (
            SCOTCH_archCmpltw(&archdat, nProcessors_, processorWeights.begin()),
            "SCOTCH_archCmpltw"
        );
    }
    else
    {
        check
        (
            SCOTCH_archCmplt(&archdat, nProcessors_),
            "SCOTCH_archCmplt"
        );
    }


    //SCOTCH_Mapping mapdat;
    //SCOTCH_graphMapInit(&grafdat, &mapdat, &archdat, NULL);
    //SCOTCH_graphMapCompute(&grafdat, &mapdat, &stradat); /* Perform mapping */
    //SCOTCH_graphMapExit(&grafdat, &mapdat);


    // Hack:switch off fpu error trapping
#   ifdef LINUX_GNUC
    int oldExcepts = fedisableexcept
    (
        FE_DIVBYZERO
      | FE_INVALID
      | FE_OVERFLOW
    );
#   endif

    finalDecomp.setSize(xadj.size()-1);
    finalDecomp = 0;
    check
    (
        SCOTCH_graphMap
        (
            &grafdat,
            &archdat,
            &stradat,           // const SCOTCH_Strat *
            finalDecomp.begin() // parttab
        ),
        "SCOTCH_graphMap"
    );

#   ifdef LINUX_GNUC
    feenableexcept(oldExcepts);
#   endif



    //finalDecomp.setSize(xadj.size()-1);
    //check
    //(
    //    SCOTCH_graphPart
    //    (
    //        &grafdat,
    //        nProcessors_,       // partnbr
    //        &stradat,           // const SCOTCH_Strat *
    //        finalDecomp.begin() // parttab
    //    ),
    //    "SCOTCH_graphPart"
    //);

    // Release storage for graph
    SCOTCH_graphExit(&grafdat);
    // Release storage for strategy
    SCOTCH_stratExit(&stradat);
    // Release storage for network topology
    SCOTCH_archExit(&archdat);

    return 0;
}
예제 #19
0
void KX_Terrain::NextFront()
{
	feenableexcept(FE_INVALID | FE_OVERFLOW);
	// Construction d'un nouveau front si celui ci est vide.
	if (m_currentFront.empty()) {
		/* La cellule de collision actuelle est après la dernière.
		 * Cela signifie aussi que toutes les propagations de velocités des
		 * cellules en collisions ont été effectué.
		 * On peut donc appliquer la velocité au positions des cellules,
		 * reconstruire l'arbre et rechercher les cellules adjacentes.
		 */
		if (m_currentCollider >= m_colliders.size()) {
			// Reconstruction de l'arbre.
			RebuildTree();

#ifdef STOP_ON_FIRST_FRAME
			if (m_time > 1.0f) {
				fedisableexcept(FE_INVALID | FE_OVERFLOW);
				return;
			}
			else {
				for (KX_CellList::iterator it = m_cells.begin(), end = m_cells.end(); it != end; ++it) {
					KX_Cell *cell = *it;
					// Aplication de la vélocité sur la position de la cellule.
					cell->Translate(m_time);
					// Reservation des calques.
					cell->ResizeVelocityLayers(m_colliders.size());
					// Recherche de toutes les cellules adjacentes à celle ci.
					cell->FindAdjacents(m_tree, m_cells);
				}
			}
			std::cout << "=================== NEXT FRAME ====================" << std::endl;
#else
			for (KX_CellList::iterator it = m_cells.begin(), end = m_cells.end(); it != end; ++it) {
				KX_Cell *cell = *it;
				// Aplication de la vélocité sur la position de la cellule.
				cell->Translate(m_time);
				// Reservation des calques.
				cell->ResizeVelocityLayers(m_colliders.size());
				// Recherche de toutes les cellules adjacentes à celle ci.
				cell->FindAdjacents(m_tree, m_cells);
			}
#endif

			// On remet à la première cellule.
			m_currentCollider = 0;
			// On incremnte le temps.
			m_time += 1.0f;
		}

		// Toutes les cellules sont remit dans l'état non calculé.
		for (KX_CellList::iterator it = m_cells.begin(), end = m_cells.end(); it != end; ++it) {
			KX_Cell *cell = *it;
			cell->ResetComputed();
		}

		const KX_ColliderInfo& colliderInfo = m_colliders[m_currentCollider];
		KX_Cell *collider = colliderInfo.cell;
		MT_Vector3 velocity = colliderInfo.velocity;

		// Application d'une velocity par défaut aux cellules de collision.
		collider->AddVelocity(velocity, m_currentCollider);

		// Création du front originel contenant que la cellule en collision.
		m_currentFront.push_back(collider);
		++m_currentCollider;
	}

	for (KX_CellList::iterator it = m_currentFront.begin(), end = m_currentFront.end(); it != end; ++it) {
		KX_Cell *cell = *it;
		/* Porpagation de la vélocité de cette cellule au cellules
		 * adjacentes pas encore calculées.
		 */
		cell->PropagateVelocity(m_currentCollider - 1);
	}

	// Nouveau front temporaire.
	KX_CellList temporaryFront;
	// Ajout des cellules adjacentes au front non calculées.
	for (KX_CellList::iterator it = m_currentFront.begin(), end = m_currentFront.end(); it != end; ++it) {
		KX_Cell *cell = *it;
		cell->AppendAjacents(temporaryFront);
	}

	// Replacment de l'ancien front.
	m_currentFront = temporaryFront;
	fedisableexcept(FE_INVALID | FE_OVERFLOW);
}
예제 #20
0
파일: fpe.c 프로젝트: cyb70289/tt
static __attribute__ ((destructor)) void fpe_deinit(void)
{
	fedisableexcept(fpe.exceptions);
	if (fpe.hooked)
		sigaction(SIGFPE, &fpe.sa, NULL);
}
예제 #21
0
/* Tests for feenableexcept/fedisableexcept.  */
static void
feenable_test (const char *flag_name, fexcept_t fe_exc)
{
  int fe_exci = fe_exc;
  double fe_excd = fe_exc;
  int excepts;

  /* First disable all exceptions.  */
  if (fedisableexcept (FE_ALL_EXCEPT) == -1)
    {
      printf ("Test: fedisableexcept (FE_ALL_EXCEPT) failed\n");
      ++count_errors;
      /* If this fails, the other tests don't make sense.  */
      return;
    }

  /* Test for inline macros using integer argument.  */
  excepts = feenableexcept (fe_exci);
  if (!EXCEPTION_ENABLE_SUPPORTED (fe_exci) && excepts == -1)
    {
      printf ("Test: not testing feenableexcept, it isn't implemented.\n");
      return;
    }
  if (excepts == -1)
    {
      printf ("Test: feenableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != 0)
    {
      printf ("Test: feenableexcept (%s) failed, return should be 0, is %x\n",
              flag_name, excepts);
      ++count_errors;
    }

  /* And now disable the exception again.  */
  excepts = fedisableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: fedisableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != fe_exc)
    {
      printf ("Test: fedisableexcept (%s) failed, return should be 0x%x, is 0x%x\n",
              flag_name, (unsigned int)fe_exc, excepts);
      ++count_errors;
    }

  /* Test for inline macros using double argument.  */
  excepts = feenableexcept (fe_excd);
  if (!EXCEPTION_ENABLE_SUPPORTED (fe_excd) && excepts == -1)
    {
      printf ("Test: not testing feenableexcept, it isn't implemented.\n");
      return;
    }
  if (excepts == -1)
    {
      printf ("Test: feenableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != 0)
    {
      printf ("Test: feenableexcept (%s) failed, return should be 0, is %x\n",
              flag_name, excepts);
      ++count_errors;
    }

  /* And now disable the exception again.  */
  excepts = fedisableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: fedisableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != fe_exc)
    {
      printf ("Test: fedisableexcept (%s) failed, return should be 0x%x, is 0x%x\n",
              flag_name, (unsigned int)fe_exc, excepts);
      ++count_errors;
    }
}
예제 #22
0
파일: amsdbc.C 프로젝트: krafczyk/AMS
void feunsetexcept_(){
fedisableexcept(FE_ALL_EXCEPT);
}
예제 #23
0
파일: fenv.c 프로젝트: SylvestreG/bitrig
/*
 * Test fegetexcept(), fedisableexcept(), and feenableexcept().
 *
 * Prerequisites: fetestexcept(), feraiseexcept()
 */
static void
test_masking(void)
{
	struct sigaction act;
	int except, i, pass, raise, status;

	assert((fegetexcept() & ALL_STD_EXCEPT) == 0);
	assert((feenableexcept(FE_INVALID|FE_OVERFLOW) & ALL_STD_EXCEPT) == 0);
	assert((feenableexcept(FE_UNDERFLOW) & ALL_STD_EXCEPT) ==
	    (FE_INVALID | FE_OVERFLOW));
	assert((fedisableexcept(FE_OVERFLOW) & ALL_STD_EXCEPT) ==
	    (FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW));
	assert((fegetexcept() & ALL_STD_EXCEPT) == (FE_INVALID | FE_UNDERFLOW));
	assert((fedisableexcept(FE_ALL_EXCEPT) & ALL_STD_EXCEPT) ==
	    (FE_INVALID | FE_UNDERFLOW));
	assert((fegetexcept() & ALL_STD_EXCEPT) == 0);

	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	act.sa_handler = trap_handler;
	for (pass = 0; pass < 2; pass++) {
		for (i = 0; i < NEXCEPTS; i++) {
			except = std_excepts[i];
			/* over/underflow may also raise inexact */
			if (except == FE_INEXACT)
				raise = FE_DIVBYZERO | FE_INVALID;
			else
				raise = ALL_STD_EXCEPT ^ except;

			/*
			 * We need to fork a child process because
			 * there isn't a portable way to recover from
			 * a floating-point exception.
			 */
			switch(fork()) {
			case 0:		/* child */
				assert((fegetexcept() & ALL_STD_EXCEPT) == 0);
				assert((feenableexcept(except)
					   & ALL_STD_EXCEPT) == 0);
				assert(fegetexcept() == except);
				raiseexcept(raise);
				assert(feraiseexcept(raise) == 0);
				assert(fetestexcept(ALL_STD_EXCEPT) == raise);

				assert(sigaction(SIGFPE, &act, NULL) == 0);
				switch (pass) {
				case 0:
					raiseexcept(except);
				case 1:
					feraiseexcept(except);
				default:
					assert(0);
				}
				assert(0);
			default:	/* parent */
				assert(wait(&status) > 0);
				/*
				 * Avoid assert() here so that it's possible
				 * to examine a failed child's core dump.
				 */
				if (!WIFEXITED(status))
					errx(1, "child aborted\n");
				assert(WEXITSTATUS(status) == 0);
				break;
			case -1:	/* error */
				assert(0);
			}
		}
	}
	assert(fetestexcept(FE_ALL_EXCEPT) == 0);
}
예제 #24
0
파일: test-fenv.c 프로젝트: alucas/glibc
/* Tests for feenableexcept/fedisableexcept/fegetexcept.  */
static void
feenable_test (const char *flag_name, int fe_exc)
{
  int excepts;

  printf ("Tests for feenableexcepts etc. with flag %s\n", flag_name);

  /* First disable all exceptions.  */
  if (fedisableexcept (FE_ALL_EXCEPT) == -1)
    {
      printf ("Test: fedisableexcept (FE_ALL_EXCEPT) failed\n");
      ++count_errors;
      /* If this fails, the other tests don't make sense.  */
      return;
    }
  excepts = fegetexcept ();
  if (excepts != 0)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0, is %d\n",
	      flag_name, excepts);
      ++count_errors;
    }
  excepts = feenableexcept (fe_exc);
  if (!EXCEPTION_ENABLE_SUPPORTED (fe_exc) && excepts == -1)
    {
      printf ("Test: not testing feenableexcept, it isn't implemented.\n");
      return;
    }
  if (excepts == -1)
    {
      printf ("Test: feenableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != 0)
    {
      printf ("Test: feenableexcept (%s) failed, return should be 0, is %x\n",
	      flag_name, excepts);
      ++count_errors;
    }

  excepts = fegetexcept ();
  if (excepts != fe_exc)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, fe_exc, excepts);
      ++count_errors;
    }

  /* And now disable the exception again.  */
  excepts = fedisableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: fedisableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != fe_exc)
    {
      printf ("Test: fedisableexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, fe_exc, excepts);
      ++count_errors;
    }

  excepts = fegetexcept ();
  if (excepts != 0)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0, is 0x%x\n",
	      flag_name, excepts);
      ++count_errors;
    }

  /* Now the other way round: Enable all exceptions and disable just this one.  */
  if (feenableexcept (FE_ALL_EXCEPT) == -1)
    {
      printf ("Test: feenableexcept (FE_ALL_EXCEPT) failed\n");
      ++count_errors;
      /* If this fails, the other tests don't make sense.  */
      return;
    }

  excepts = fegetexcept ();
  if (excepts != FE_ALL_EXCEPT)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, FE_ALL_EXCEPT, excepts);
      ++count_errors;
    }

  excepts = fedisableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: fedisableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != FE_ALL_EXCEPT)
    {
      printf ("Test: fedisableexcept (%s) failed, return should be 0, is 0x%x\n",
	      flag_name, excepts);
      ++count_errors;
    }

  excepts = fegetexcept ();
  if (excepts != (FE_ALL_EXCEPT & ~fe_exc))
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, (FE_ALL_EXCEPT & ~fe_exc), excepts);
      ++count_errors;
    }

  /* And now enable the exception again.  */
  excepts = feenableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: feenableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != (FE_ALL_EXCEPT & ~fe_exc))
    {
      printf ("Test: feenableexcept (%s) failed, return should be 0, is 0x%x\n",
	      flag_name, excepts);
      ++count_errors;
    }

  excepts = fegetexcept ();
  if (excepts != FE_ALL_EXCEPT)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, FE_ALL_EXCEPT, excepts);
      ++count_errors;
    }
  feexcp_nomask_test (flag_name, fe_exc);
  feexcp_mask_test (flag_name, fe_exc);

}
예제 #25
0
파일: test-fenv.c 프로젝트: alucas/glibc
static void
feholdexcept_tests (void)
{
  fenv_t saved, saved2;
  int res;

  feclearexcept (FE_ALL_EXCEPT);
  fedisableexcept (FE_ALL_EXCEPT);
#ifdef FE_DIVBYZERO
  feraiseexcept (FE_DIVBYZERO);
#endif
  test_exceptions ("feholdexcept_tests FE_DIVBYZERO test",
		   DIVBYZERO_EXC, 0);
  res = feholdexcept (&saved);
  if (res != 0)
    {
      printf ("feholdexcept failed: %d\n", res);
      ++count_errors;
    }
#if defined FE_TONEAREST && defined FE_TOWARDZERO
  res = fesetround (FE_TOWARDZERO);
  if (res != 0)
    {
      printf ("fesetround failed: %d\n", res);
      ++count_errors;
    }
#endif
  test_exceptions ("feholdexcept_tests 0 test", NO_EXC, 0);
#ifdef FE_INVALID
  feraiseexcept (FE_INVALID);
  test_exceptions ("feholdexcept_tests FE_INVALID test",
		   INVALID_EXC, 0);
#endif
  res = feupdateenv (&saved);
  if (res != 0)
    {
      printf ("feupdateenv failed: %d\n", res);
      ++count_errors;
    }
#if defined FE_TONEAREST && defined FE_TOWARDZERO
  res = fegetround ();
  if (res != FE_TONEAREST)
    {
      printf ("feupdateenv didn't restore rounding mode: %d\n", res);
      ++count_errors;
    }
#endif
  test_exceptions ("feholdexcept_tests FE_DIVBYZERO|FE_INVALID test",
		   DIVBYZERO_EXC | INVALID_EXC, 0);
  feclearexcept (FE_ALL_EXCEPT);
#ifdef FE_INVALID
  feraiseexcept (FE_INVALID);
#endif
#if defined FE_TONEAREST && defined FE_UPWARD
  res = fesetround (FE_UPWARD);
  if (res != 0)
    {
      printf ("fesetround failed: %d\n", res);
      ++count_errors;
    }
#endif
  res = feholdexcept (&saved2);
  if (res != 0)
    {
      printf ("feholdexcept failed: %d\n", res);
      ++count_errors;
    }
#if defined FE_TONEAREST && defined FE_UPWARD
  res = fesetround (FE_TONEAREST);
  if (res != 0)
    {
      printf ("fesetround failed: %d\n", res);
      ++count_errors;
    }
#endif
  test_exceptions ("feholdexcept_tests 0 2nd test", NO_EXC, 0);
#ifdef FE_INEXACT
  feraiseexcept (FE_INEXACT);
  test_exceptions ("feholdexcept_tests FE_INEXACT test",
		   INEXACT_EXC, 0);
#endif
  res = feupdateenv (&saved2);
  if (res != 0)
    {
      printf ("feupdateenv failed: %d\n", res);
      ++count_errors;
    }
#if defined FE_TONEAREST && defined FE_UPWARD
  res = fegetround ();
  if (res != FE_UPWARD)
    {
      printf ("feupdateenv didn't restore rounding mode: %d\n", res);
      ++count_errors;
    }
  fesetround (FE_TONEAREST);
#endif
  test_exceptions ("feholdexcept_tests FE_INEXACT|FE_INVALID test",
		   INVALID_EXC | INEXACT_EXC, 0);
  feclearexcept (FE_ALL_EXCEPT);
}
예제 #26
0
파일: test-fenv.c 프로젝트: alucas/glibc
/* Test that program doesn't abort with exception.  */
static void
feexcp_mask_test (const char *flag_name, int fe_exc)
{
  int status;
  int exception;
  pid_t pid;

  printf ("Test: after fedisableexcept (%s) processes will not abort\n",
	  flag_name);
  printf ("      when feraiseexcept (%s) is called.\n", flag_name);
  pid = fork ();
  if (pid == 0)
    {
#ifdef RLIMIT_CORE
      /* Try to avoid dumping core.  */
      struct rlimit core_limit;
      core_limit.rlim_cur = 0;
      core_limit.rlim_max = 0;
      setrlimit (RLIMIT_CORE, &core_limit);
#endif
      feenableexcept (FE_ALL_EXCEPT);
      exception = fe_exc;
#ifdef FE_INEXACT
      /* The standard allows the inexact exception to be set together with the
	 underflow and overflow exceptions.  So add FE_INEXACT to the set of
	 exceptions to be disabled if we will be raising underflow or
	 overflow.  */
# ifdef FE_OVERFLOW
      if (fe_exc & FE_OVERFLOW)
	exception |= FE_INEXACT;
# endif
# ifdef FE_UNDERFLOW
      if (fe_exc & FE_UNDERFLOW)
	exception |= FE_INEXACT;
# endif
#endif
      fedisableexcept (exception);
      feraiseexcept (fe_exc);
      exit (2);
    }
  else if (pid < 0)
    {
      if (errno != ENOSYS)
	{
	  printf ("  Fail: Could not fork.\n");
	  ++count_errors;
	}
      else
	printf ("  `fork' not implemented, test ignored.\n");
    }
  else {
    if (waitpid (pid, &status, 0) != pid)
      {
	printf ("  Fail: waitpid call failed.\n");
	++count_errors;
      }
    else if (WIFEXITED (status) && WEXITSTATUS (status) == 2)
      printf ("  Pass: Process exited normally.\n");
    else
      {
	printf ("  Fail: Process exited abnormally with status %d.\n",
		status);
	++count_errors;
      }
  }
}
예제 #27
0
bool inverse4x4(float m[],float invOut[])
{
    float inv[16], det;
    uint8_t i;

#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
    int old = fedisableexcept(FE_OVERFLOW);
    if (old < 0) {
        hal.console->printf("inverse4x4(): warning: error on disabling FE_OVERFLOW floating point exception\n");
    }
#endif

    inv[0] = m[5]  * m[10] * m[15] -
    m[5]  * m[11] * m[14] -
    m[9]  * m[6]  * m[15] +
    m[9]  * m[7]  * m[14] +
    m[13] * m[6]  * m[11] -
    m[13] * m[7]  * m[10];

    inv[4] = -m[4]  * m[10] * m[15] +
    m[4]  * m[11] * m[14] +
    m[8]  * m[6]  * m[15] -
    m[8]  * m[7]  * m[14] -
    m[12] * m[6]  * m[11] +
    m[12] * m[7]  * m[10];

    inv[8] = m[4]  * m[9] * m[15] -
    m[4]  * m[11] * m[13] -
    m[8]  * m[5] * m[15] +
    m[8]  * m[7] * m[13] +
    m[12] * m[5] * m[11] -
    m[12] * m[7] * m[9];

    inv[12] = -m[4]  * m[9] * m[14] +
    m[4]  * m[10] * m[13] +
    m[8]  * m[5] * m[14] -
    m[8]  * m[6] * m[13] -
    m[12] * m[5] * m[10] +
    m[12] * m[6] * m[9];

    inv[1] = -m[1]  * m[10] * m[15] +
    m[1]  * m[11] * m[14] +
    m[9]  * m[2] * m[15] -
    m[9]  * m[3] * m[14] -
    m[13] * m[2] * m[11] +
    m[13] * m[3] * m[10];

    inv[5] = m[0]  * m[10] * m[15] -
    m[0]  * m[11] * m[14] -
    m[8]  * m[2] * m[15] +
    m[8]  * m[3] * m[14] +
    m[12] * m[2] * m[11] -
    m[12] * m[3] * m[10];

    inv[9] = -m[0]  * m[9] * m[15] +
    m[0]  * m[11] * m[13] +
    m[8]  * m[1] * m[15] -
    m[8]  * m[3] * m[13] -
    m[12] * m[1] * m[11] +
    m[12] * m[3] * m[9];

    inv[13] = m[0]  * m[9] * m[14] -
    m[0]  * m[10] * m[13] -
    m[8]  * m[1] * m[14] +
    m[8]  * m[2] * m[13] +
    m[12] * m[1] * m[10] -
    m[12] * m[2] * m[9];

    inv[2] = m[1]  * m[6] * m[15] -
    m[1]  * m[7] * m[14] -
    m[5]  * m[2] * m[15] +
    m[5]  * m[3] * m[14] +
    m[13] * m[2] * m[7] -
    m[13] * m[3] * m[6];

    inv[6] = -m[0]  * m[6] * m[15] +
    m[0]  * m[7] * m[14] +
    m[4]  * m[2] * m[15] -
    m[4]  * m[3] * m[14] -
    m[12] * m[2] * m[7] +
    m[12] * m[3] * m[6];

    inv[10] = m[0]  * m[5] * m[15] -
    m[0]  * m[7] * m[13] -
    m[4]  * m[1] * m[15] +
    m[4]  * m[3] * m[13] +
    m[12] * m[1] * m[7] -
    m[12] * m[3] * m[5];

    inv[14] = -m[0]  * m[5] * m[14] +
    m[0]  * m[6] * m[13] +
    m[4]  * m[1] * m[14] -
    m[4]  * m[2] * m[13] -
    m[12] * m[1] * m[6] +
    m[12] * m[2] * m[5];

    inv[3] = -m[1] * m[6] * m[11] +
    m[1] * m[7] * m[10] +
    m[5] * m[2] * m[11] -
    m[5] * m[3] * m[10] -
    m[9] * m[2] * m[7] +
    m[9] * m[3] * m[6];

    inv[7] = m[0] * m[6] * m[11] -
    m[0] * m[7] * m[10] -
    m[4] * m[2] * m[11] +
    m[4] * m[3] * m[10] +
    m[8] * m[2] * m[7] -
    m[8] * m[3] * m[6];

    inv[11] = -m[0] * m[5] * m[11] +
    m[0] * m[7] * m[9] +
    m[4] * m[1] * m[11] -
    m[4] * m[3] * m[9] -
    m[8] * m[1] * m[7] +
    m[8] * m[3] * m[5];

    inv[15] = m[0] * m[5] * m[10] -
    m[0] * m[6] * m[9] -
    m[4] * m[1] * m[10] +
    m[4] * m[2] * m[9] +
    m[8] * m[1] * m[6] -
    m[8] * m[2] * m[5];

    det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];

#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
    if (old >= 0 && feenableexcept(old) < 0) {
        hal.console->printf("inverse4x4(): warning: error on restoring floating exception mask\n");
    }
#endif

    if (is_zero(det) || isinf(det)){
        return false;
    }

    det = 1.0f / det;

    for (i = 0; i < 16; i++)
        invOut[i] = inv[i] * det;
    return true;
}
예제 #28
0
파일: vmath.c 프로젝트: Gordath/mars2030
void disable_fpexcept(void)
{
	fedisableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);
}
예제 #29
0
// Call scotch with options from dictionary.
Foam::label Foam::ptscotchDecomp::decompose
(
    const fileName& meshPath,
    const List<int>& adjncy,
    const List<int>& xadj,
    const scalarField& cWeights,

    List<int>& finalDecomp
) const
{
    if (debug)
    {
        Pout<< "ptscotchDecomp : entering with xadj:" << xadj.size() << endl;
    }

    // Dump graph
    if (decompositionDict_.found("ptscotchCoeffs"))
    {
        const dictionary& scotchCoeffs =
            decompositionDict_.subDict("ptscotchCoeffs");

        if (scotchCoeffs.lookupOrDefault("writeGraph", false))
        {
            OFstream str
            (
               meshPath + "_" + Foam::name(Pstream::myProcNo()) + ".dgr"
            );

            Pout<< "Dumping Scotch graph file to " << str.name() << endl
                << "Use this in combination with dgpart." << endl;

            globalIndex globalCells(xadj.size()-1);

            // Distributed graph file (.grf)
            label version = 2;
            str << version << nl;
            // Number of files (procglbnbr)
            str << Pstream::nProcs();
            // My file number (procloc)
            str << ' ' << Pstream::myProcNo() << nl;

            // Total number of vertices (vertglbnbr)
            str << globalCells.size();
            // Total number of connections (edgeglbnbr)
            str << ' ' << returnReduce(xadj[xadj.size()-1], sumOp<label>())
                << nl;
            // Local number of vertices (vertlocnbr)
            str << xadj.size()-1;
            // Local number of connections (edgelocnbr)
            str << ' ' << xadj[xadj.size()-1] << nl;
            // Numbering starts from 0
            label baseval = 0;
            // 100*hasVertlabels+10*hasEdgeWeights+1*hasVertWeighs
            str << baseval << ' ' << "000" << nl;
            for (label cellI = 0; cellI < xadj.size()-1; cellI++)
            {
                label start = xadj[cellI];
                label end = xadj[cellI+1];
                str << end-start;

                for (label i = start; i < end; i++)
                {
                    str << ' ' << adjncy[i];
                }
                str << nl;
            }
        }
    }

    // Strategy
    // ~~~~~~~~

    // Default.
    SCOTCH_Strat stradat;
    check(SCOTCH_stratInit(&stradat), "SCOTCH_stratInit");

    if (decompositionDict_.found("scotchCoeffs"))
    {
        const dictionary& scotchCoeffs =
            decompositionDict_.subDict("scotchCoeffs");


        string strategy;
        if (scotchCoeffs.readIfPresent("strategy", strategy))
        {
            if (debug)
            {
                Info<< "ptscotchDecomp : Using strategy " << strategy << endl;
            }
            SCOTCH_stratDgraphMap(&stradat, strategy.c_str());
            //fprintf(stdout, "S\tStrat=");
            //SCOTCH_stratSave(&stradat, stdout);
            //fprintf(stdout, "\n");
        }
    }


    // Graph
    // ~~~~~

    List<int> velotab;


    // Check for externally provided cellweights and if so initialise weights
    scalar minWeights = gMin(cWeights);
    if (cWeights.size() > 0)
    {
        if (minWeights <= 0)
        {
            WarningIn
            (
                "ptscotchDecomp::decompose(..)"
            )   << "Illegal minimum weight " << minWeights
                << endl;
        }

        if (cWeights.size() != xadj.size()-1)
        {
            FatalErrorIn
            (
                "ptscotchDecomp::decompose(..)"
            )   << "Number of cell weights " << cWeights.size()
                << " does not equal number of cells " << xadj.size()-1
                << exit(FatalError);
        }

        // Convert to integers.
        velotab.setSize(cWeights.size());
        forAll(velotab, i)
        {
            velotab[i] = int(cWeights[i]/minWeights);
        }
    }



    if (debug)
    {
        Pout<< "SCOTCH_dgraphInit" << endl;
    }
    SCOTCH_Dgraph grafdat;
    check(SCOTCH_dgraphInit(&grafdat, MPI_COMM_WORLD), "SCOTCH_dgraphInit");


    if (debug)
    {
        Pout<< "SCOTCH_dgraphBuild with:" << nl
            << "xadj.size()-1   : " << xadj.size()-1 << nl
            << "xadj            : " << long(xadj.begin()) << nl
            << "velotab         : " << long(velotab.begin()) << nl
            << "adjncy.size()   : " << adjncy.size() << nl
            << "adjncy          : " << long(adjncy.begin()) << nl
            << endl;
    }

    check
    (
        SCOTCH_dgraphBuild
        (
            &grafdat,               // grafdat
            0,                      // baseval, c-style numbering
            xadj.size()-1,          // vertlocnbr, nCells
            xadj.size()-1,          // vertlocmax
            const_cast<SCOTCH_Num*>(xadj.begin()),
                                    // vertloctab, start index per cell into
                                    // adjncy
            const_cast<SCOTCH_Num*>(&xadj[1]),// vendloctab, end index  ,,

            const_cast<SCOTCH_Num*>(velotab.begin()),// veloloctab, vtx weights
            NULL,                   // vlblloctab

            adjncy.size(),          // edgelocnbr, number of arcs
            adjncy.size(),          // edgelocsiz
            const_cast<SCOTCH_Num*>(adjncy.begin()),         // edgeloctab
            NULL,                   // edgegsttab
            NULL                    // edlotab, edge weights
        ),
        "SCOTCH_dgraphBuild"
    );


    if (debug)
    {
        Pout<< "SCOTCH_dgraphCheck" << endl;
    }
    check(SCOTCH_dgraphCheck(&grafdat), "SCOTCH_dgraphCheck");


    // Architecture
    // ~~~~~~~~~~~~
    // (fully connected network topology since using switch)

    if (debug)
    {
        Pout<< "SCOTCH_archInit" << endl;
    }
    SCOTCH_Arch archdat;
    check(SCOTCH_archInit(&archdat), "SCOTCH_archInit");

    List<label> processorWeights;
    if (decompositionDict_.found("scotchCoeffs"))
    {
        const dictionary& scotchCoeffs =
            decompositionDict_.subDict("scotchCoeffs");

        scotchCoeffs.readIfPresent("processorWeights", processorWeights);
    }
    if (processorWeights.size())
    {
        if (debug)
        {
            Info<< "ptscotchDecomp : Using procesor weights "
                << processorWeights
                << endl;
        }
        check
        (
            SCOTCH_archCmpltw(&archdat, nProcessors_, processorWeights.begin()),
            "SCOTCH_archCmpltw"
        );
    }
    else
    {
        if (debug)
        {
            Pout<< "SCOTCH_archCmplt" << endl;
        }
        check
        (
            SCOTCH_archCmplt(&archdat, nProcessors_),
            "SCOTCH_archCmplt"
        );
    }


    //SCOTCH_Mapping mapdat;
    //SCOTCH_dgraphMapInit(&grafdat, &mapdat, &archdat, NULL);
    //SCOTCH_dgraphMapCompute(&grafdat, &mapdat, &stradat); /*Perform mapping*/
    //SCOTCHdgraphMapExit(&grafdat, &mapdat);


    // Hack:switch off fpu error trapping
#   ifdef LINUX_GNUC
    int oldExcepts = fedisableexcept
    (
        FE_DIVBYZERO
      | FE_INVALID
      | FE_OVERFLOW
    );
#   endif

    if (debug)
    {
        Pout<< "SCOTCH_dgraphMap" << endl;
    }
    finalDecomp.setSize(xadj.size()-1);
    finalDecomp = 0;
    check
    (
        SCOTCH_dgraphMap
        (
            &grafdat,
            &archdat,
            &stradat,           // const SCOTCH_Strat *
            finalDecomp.begin() // parttab
        ),
        "SCOTCH_graphMap"
    );

#   ifdef LINUX_GNUC
    feenableexcept(oldExcepts);
#   endif



    //finalDecomp.setSize(xadj.size()-1);
    //check
    //(
    //    SCOTCH_dgraphPart
    //    (
    //        &grafdat,
    //        nProcessors_,       // partnbr
    //        &stradat,           // const SCOTCH_Strat *
    //        finalDecomp.begin() // parttab
    //    ),
    //    "SCOTCH_graphPart"
    //);

    if (debug)
    {
        Pout<< "SCOTCH_dgraphExit" << endl;
    }
    // Release storage for graph
    SCOTCH_dgraphExit(&grafdat);
    // Release storage for strategy
    SCOTCH_stratExit(&stradat);
    // Release storage for network topology
    SCOTCH_archExit(&archdat);

    return 0;
}
예제 #30
0
void DisableFPE()
{
#if defined(_GNU_SOURCE) && !defined(__APPLE__)
	fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
#endif
}