<s> import pytest <EOL> import numpy <EOL> from random import randrange <EOL> from pyop2 import plan as _plan <EOL> from pyop2 import op2 <EOL> backends = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> valuetype = numpy . float64 <EOL> NUM_ELE = <NUM_LIT:12> <EOL> NUM_NODES = <NUM_LIT> <EOL> NUM_ENTRIES = <NUM_LIT:4> <EOL> class TestColoring : <EOL> """<STR_LIT>""" <EOL> @ pytest . fixture <EOL> def nodes ( cls ) : <EOL> return op2 . Set ( NUM_NODES , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def elements ( cls ) : <EOL> return op2 . Set ( NUM_ELE , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def dnodes ( cls , nodes ) : <EOL> return op2 . DataSet ( nodes , <NUM_LIT:1> , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def elem_node_map ( cls ) : <EOL> v = [ randrange ( NUM_ENTRIES ) for i in range ( NUM_ELE * <NUM_LIT:3> ) ] <EOL> return numpy . asarray ( v , dtype = numpy . uint32 ) <EOL> @ pytest . fixture <EOL> def elem_node ( cls , elements , nodes , elem_node_map ) : <EOL> return op2 . Map ( elements , nodes , <NUM_LIT:3> , elem_node_map , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def mat ( cls , elem_node , dnodes ) : <EOL> sparsity = op2 . Sparsity ( ( dnodes , dnodes ) , ( elem_node , elem_node ) , "<STR_LIT>" ) <EOL> return op2 . Mat ( sparsity , valuetype , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def x ( cls , dnodes ) : <EOL> return op2 . Dat ( dnodes , numpy . zeros ( NUM_NODES , dtype = numpy . uint32 ) , numpy . uint32 , "<STR_LIT:x>" ) <EOL> def test_thread_coloring ( self , backend , skip_opencl , elements , elem_node_map , elem_node , mat , x ) : <EOL> assert NUM_ELE % <NUM_LIT:2> == <NUM_LIT:0> , "<STR_LIT>" <EOL> plan = _plan . Plan ( elements . all_part , <EOL> mat ( op2 . INC , ( elem_node [ op2 . i [ <NUM_LIT:0> ] ] , <EOL> elem_node [ op2 . i [ <NUM_LIT:1> ] ] ) ) , <EOL> x ( op2 . WRITE , elem_node [ <NUM_LIT:0> ] ) , <EOL> partition_size = NUM_ELE / <NUM_LIT:2> , <EOL> matrix_coloring = True ) <EOL> assert plan . nblocks == <NUM_LIT:2> <EOL> eidx = <NUM_LIT:0> <EOL> for p in range ( plan . nblocks ) : <EOL> for thrcol in range ( plan . nthrcol [ p ] ) : <EOL> counter = numpy . zeros ( NUM_NODES , dtype = numpy . uint32 ) <EOL> for e in range ( eidx , eidx + plan . nelems [ p ] ) : <EOL> if plan . thrcol [ e ] == thrcol : <EOL> counter [ elem_node . values [ e ] [ <NUM_LIT:0> ] ] += <NUM_LIT:1> <EOL> assert ( counter < <NUM_LIT:2> ) . all ( ) <EOL> eidx += plan . nelems [ p ] </s>
