Compiling P Arallel Sparse Co de for UserDefined Data

Embed Size (px)

Citation preview

  • 8/11/2019 Compiling P Arallel Sparse Co de for UserDefined Data

    1/9

    C o m p i l i n g P a r a l l e l S p a r s e C o d e f o r U s e r - D e n e d D a t a

    S t r u c t u r e s

    y

    V l a d i m i r K o t l y a r , K e s h a v P i n g a l i a n d P a u l S t o d g h i l l

    D e p a r t m e n t o f C o m p u t e r S c i e n c e

    C o r n e l l U n i v e r s i t y , I t h a c a , N Y 1 4 8 5 3

    f v l a d i m i r , p i n g a l i , s t o d g h i l g @ c s . c o r n e l l . e d u

    J u n e 2 , 1 9 9 7

    A b s t r a c t

    W e d e s c r i b e h o w v a r i o u s s p a r s e m a t r i x a n d d i s t r i b u t i o n f o r m a t s c a n b e h a n d l e d u s i n g

    t h e r e l a t i o n a l a p p r o a c h t o s p a r s e m a t r i x c o d e c o m p i l a t i o n . T h i s a p p r o a c h a l l o w s f o r t h e

    d e v e l o p m e n t o f c o m p i l a t i o n t e c h n i q u e s t h a t a r e i n d e p e n d e n t o f t h e s t o r a g e f o r m a t s b y v i e w i n g

    t h e d a t a s t r u c t u r e s a s r e l a t i o n s a n d a b s t r a c t i n g t h e i m p l e m e n t a t i o n d e t a i l s a s a c c e s s m e t h o d s .

    1 I n t r o d u c t i o n

    S p a r s e m a t r i x c o m p u t a t i o n s a r e a t t h e c o r e o f m a n y c o m p u t a t i o n a l s c i e n c e a l g o r i t h m s . A t y p i c a l

    a p p l i c a t i o n c a n o f t e n b e s e p a r a t e d i n t o t h e d i s c r e t i z a t i o n m o d u l e , w h i c h t r a n s l a t e s a c o n t i n u o u s

    p r o b l e m ( s u c h a s a s y s t e m o f d i e r e n t i a l e q u a t i o n s ) i n t o a s e q u e n c e o f s p a r s e m a t r i x p r o b l e m s , a n d

    i n t o t h e s o l v e r m o d u l e , w h i c h s o l v e s t h e m a t r i x p r o b l e m s . T y p i c a l l y , t h e s o l v e r i s t h e m o s t t i m e -

    a n d s p a c e - i n t e n s i v e p a r t o f a n a p p l i c a t i o n a n d , q u i t e n a t u r a l l y , m u c h e o r t b o t h i n t h e n u m e r i c a l

    a n a l y s i s a n d c o m p i l e r s c o m m u n i t i e s h a s b e e n d e v o t e d t o p r o d u c i n g e c i e n t p a r a l l e l a n d s e q u e n t i a l

    c o d e f o r s p a r s e m a t r i x s o l v e r s . T h e r e a r e t w o c h a l l e n g e s i n g e n e r a t i n g s o l v e r c o d e t h a t h a s t o b e

    i n t e r f a c e d w i t h d i s c r e t i z a t i o n s y s t e m s :

    D i e r e n t d i s c r e t i z a t i o n s y s t e m s p r o d u c e t h e s p a r s e m a t r i c e s i n m a n y d i e r e n t f o r m a t s .

    T h e r e f o r e , t h e c o m p i l e r s h o u l d b e a b l e t o g e n e r a t e s o l v e r c o d e f o r d i e r e n t s t o r a g e f o r m a t s .

    S o m e d i s c r e t i z a t i o n s y s t e m s p a r t i t i o n t h e p r o b l e m f o r p a r a l l e l s o l u t i o n , a n d u s e v a r i o u s

    m e t h o d s f o r s p e c i f y i n g t h e p a r t i t i o n i n g ( d i s t r i b u t i o n ) . T h e r e f o r e , a c o m p i l e r s h o u l d b e a b l e

    t o p r o d u c e p a r a l l e l c o d e f o r d i e r e n t d i s t r i b u t i o n f o r m a t s .

    I n o u r a p p r o a c h , t h e p r o g r a m m e r w r i t e s p r o g r a m s a s i f a l l m a t r i c e s w e r e d e n s e , a n d t h e n

    p r o v i d e s a s p e c i c a t i o n o f w h i c h m a t r i c e s a r e a c t u a l l y s p a r s e , a n d w h a t f o r m a t s / d i s t r i b u t i o n s a r e

    u s e d t o r e p r e s e n t t h e m . T h e j o b o f t h e c o m p i l e r i s t h e f o l l o w i n g : g i v e n a s e q u e n t i a l , d e n s e m a t r i x

    p r o g r a m , d e s c r i p t i o n s o f s p a r s e m a t r i x f o r m a t s a n d d a t a a n d c o m p u t a t i o n d i s t r i b u t i o n f o r m a t s ,

    g e n e r a t e p a r a l l e l s p a r s e S P M D c o d e . 5 ] a n d 6 ] h a v e i n t r o d u c e d a r e l a t i o n a l a l g e b r a a p p r o a c h

    t o s o l v i n g t h i s p r o b l e m . I n t h i s a p p r o a c h , w e v i e w s p a r s e m a t r i c e s a s d a t a b a s e r e l a t i o n s , s p a r s e

    m a t r i x f o r m a t s a s i m p l e m e n t a t i o n s o f a c c e s s m e t h o d s t o t h e r e l a t i o n s , a n d e x e c u t i o n o f l o o p n e s t s

    a s e v a l u a t i o n o f c e r t a i n r e l a t i o n a l q u e r i e s . T h e k e y o p e r a t o r i n t h e s e q u e r i e s t u r n s o u t t o b e t h e

    r e l a t i o n a l j o i n . F o r p a r a l l e l e x e c u t i o n , w e v i e w l o o p n e s t s a s d i s t r i b u t e d q u e r i e s a n d t h e p r o c e s s

    T h i s r e s e a r c h w a s s u p p o r t e d b y a n N S F P r e s i d e n t i a l Y o u n g I n v e s t i g a t o r a w a r d C C R - 8 9 5 8 5 4 3 , N S F

    G r a n t C C R 9 5 0 3 1 9 9 a n d O N R g r a n t N 0 0 0 1 4 - 9 3 - 1 - 0 1 0 3 .

    y

    A v e r s i o n o f t h i s r e p o r t a p p e a r s i n t h e p r o c e e d i n g s o f E i g h t h S I A M C o n f e r e n c e o n P a r a l l e l P r o c e s s i n g

    f o r S c i e n t i c C o m p u t i n g

    1

  • 8/11/2019 Compiling P Arallel Sparse Co de for UserDefined Data

    2/9

    2

    o f g e n e r a t i n g S P M D n o d e p r o g r a m s a s t h e t r a n s l a t i o n o f d i s t r i b u t e d q u e r i e s i n t o e q u i v a l e n t l o c a l

    q u e r i e s a n d c o m m u n i c a t i o n s t a t e m e n t s .

    I n t h i s p a p e r , w e f o c u s o n h o w o u r c o m p i l e r h a n d l e s u s e r - d e n e d s p a r s e d a t a s t r u c t u r e s a n d

    d i s t r i b u t i o n f o r m a t s . T h e a r c h i t e c t u r e o f t h e c o m p i l e r i s i l l u s t r a t e d i n F i g u r e 1 .

    SPMD translation

    Optimizations

    Join Scheduling

    Code Generation

    Join Implementation Data StructureDescriptions

    Hierarchy, Costs

    AM properties, Costs

    AM & Index properties

    AM implementation

    F i g . 1 . A r c h i t e c t u r e o f t h e C o m p i l e r

    S P M D t r a n s l a t i o n p h a s e t a k e s a n H P F - l i k e p a r a l l e l p r o g r a m d e s c r i p t i o n a n d t r a n s l a t e s i t i n t o

    S P M D n o d e p r o g r a m s . 6 ] d e s c r i b e s t h i s p r o c e s s a s d i s t r i b u t e d q u e r y e v a l u a t i o n . S e c t i o n 4

    s h o w s h o w d i e r e n t d i s t r i b u t i o n f o r m a t s a r e h a n d l e d b y t h e c o m p i l e r .

    J o i n S c h e d u l e r a n d J o i n I m p l e m e n t e r , d e s c r i b e d i n d e t a i l i n 5 ] , e x t r a c t r e l a t i o n a l e x p r e s s i o n s

    d e s c r i b i n g t h e c o m p u t a t i o n s t h a t m u s t b e p e r f o r m e d , a n d d e c i d e h o w t h e s e e x p r e s s i o n s s h o u l d

    b e e v a l u a t e d . T h e r e s u l t i s a h i g h - l e v e l p r o g r a m , c a l l e d a p l a n , i n t e r m s o f a b s t r a c t a c c e s s

    m e t h o d s ( A M s ) t o t h e r e l a t i o n s .

    M a n y s p a r s e s t o r a g e f o r m a t s h a v e a h i e r a r c h i c a l s t r u c t u r e . F o r e x a m p l e , t h e c o m p r e s s e d r o w

    f o r m a t ( 7 ] ) a l l o w s a c c e s s r s t b y r o w a n d t h e n b y c o l u m n . T h e s c h e d u l e r a n d i m p l e m e n t e r

    u s e t h i s i n f o r m a t i o n a l o n g w i t h t h e i n f o r m a t i o n a b o u t t h e p r o p e r t i e s o f t h e i n d i c e s s t o r e d i n

    t h e m a t r i x a n d t h e c o s t s o f t h e a c c e s s m e t h o d s i n o r d e r t o p r o d u c e a n o p t i m i z e d p l a n . S e c t i o n

    2 e x p l a i n s h o w t h i s i n f o r m a t i o n i s p r o v i d e d t o t h e c o m p i l e r .

    O p t i m i z e r f u r t h e r o p t i m i z e s t h e p l a n . T h e n e e d f o r o p t i m i z a t i o n s i n u e n c e s t h e d e s i g n o f

    t h e i n t e r f a c e b e t w e e n d a t a s t r u c t u r e d e s c r i p t i o n s a n d t h e c o m p i l e r . W e i l l u s t r a t e t h i s o n a n

    e x a m p l e i n S e c t i o n 2 . 6 .

    C o d e G e n e r a t o r t r a n s l a t e s t h e p l a n i n t o l o w - l e v e l ( e . g . , C o r F o r t r a n ) c o d e b y i n s t a n t i a t i n g

    t h e c a l l s t o a c c e s s m e t h o d s . T h i s i s d e s c r i b e d i n S e c t i o n 3 .

    I n t h e r e s t o f t h e p a p e r , w e d e s c r i b e h o w t h e s e p h a s e s o f t h e c o m p i l e r i n t e r f a c e u s e r - d e n e d

    d a t a s t r u c t u r e s .

    2 D e s c r i b i n g R e l a t i o n s t o t h e C o m p i l e r

    2 . 1 A M o t i v a t i n g E x a m p l e

    W e u s e s p a r s e m a t r i x - v e c t o r m u l t i p l i c a t i o n a s a r u n n i n g e x a m p l e :

    D O i = 1 n

    D O j = 1 n

    Y ( i ) = Y ( i ) + A ( i j ) X ( j )

  • 8/11/2019 Compiling P Arallel Sparse Co de for UserDefined Data

    3/9

    3

    W e a s s u m e t h a t t h e m a t r i x A i s s p a r s e a n d t h e v e c t o r s X a n d Y a r e d e n s e . I t i s s h o w n i n 5 ] t h a t

    e x e c u t i o n o f t h i s l o o p c a n b e v i e w e d a s e v a l u a t i o n o f a r e l a t i o n a l q u e r y :

    Q ( i j v

    A

    v

    y

    v

    x

    ) =

    P

    I ( i j ) . / A ( i j v

    A

    ) . / Y ( i v

    y

    ) . / X ( j v

    x

    )

    ( 1 )

    w i t h t h e p r e d i c a t e P d e n e d a s :

    P

    d e f

    = N Z ( A ( i j ) ) N Z ( X ( j ) ) ( 2 )

    I n t h i s q u e r y I ( i j ) i s t h e r e l a t i o n t h a t r e p r e s e n t s t h e s e t o f t h e i t e r a t i o n s o f t h e l o o p , A ( i j v

    A

    )

    i s t h e r e l a t i o n t h a t s t o r e s t h e v a l u e s v

    A

    o f t h e m a t r i x A , X s t o r e s x , Y s t o r e s y . C o n c e p t u a l l y ,

    t h e r e l a t i o n s s t o r e b o t h z e r o s a n d n o n - z e r o s . A l t h o u g h i t m i g h t b e t h e c a s e t h a t o n l y n o n - z e r o s

    a r e p h y s i c a l l y s t o r e d . T h e p r e d i c a t e s N Z ( A ( i j ) ) a n d N Z ( X ( j ) ) t e s t i f a p a r t i c u l a r a r r a y e l e m e n t

    i s i n d e e d p h y s i c a l l y s t o r e d a n d h a s t o b e a s s u m e d t o h a v e a n o n - z e r o v a l u e . N o t i c e t h a t t h e N Z

    p r e d i c a t e i s t r u e f o r a l l i n d i c e s o f a d e n s e a r r a y , e v e n i f s o m e v a l u e s a r e n u m e r i c a l l y z e r o .

    T h i s q u e r y ( 1 ) c o n t a i n s t w o j o i n s : o n i a n d o n j . T h e o r d e r o f t h e n e s t i n g o f t h e j o i n s i n t h e

    n a l c o d e d e p e n d s o n h o w t h e m a t r i x A i s s t o r e d . F o r e x a m p l e , i f t h e m a t r i x w e r e s t o r e d u s i n g

    c o m p r e s s e d r o w f o r m a t ( C R S ) , t h e n t h e o u t e r l o o p o f t h e r e s u l t i n g c o d e e n u m e r a t e s t h e r o w s ( i ' s )

    a n d t h e i n n e r l o o p w a l k s w i t h i n e a c h r o w a n d s e a r c h e s i n t o t h e v e c t o r s ( F i g u r e 2 ) . O n t h e o t h e r

    D O i = 1 n

    D O h v

    A

    j i 2 A ( i )

    v

    y

    = s e a r c h Y f o r i

    v

    x

    = s e a r c h X f o r j

    v

    y

    = v

    y

    + v

    A

    v

    x

    F i g . 2 . M V M f o r C R S f o r m a t

    D O j = 1 n

    D O h v

    A

    i i 2 A ( j )

    v

    y

    = s e a r c h Y f o r i

    v

    x

    = s e a r c h X f o r j

    v

    y

    = v

    y

    + v

    A

    v

    x

    F i g . 3 . M V M f o r C C S f o r m a t

    h a n d , i f t h e m a t r i x w e r e s t o r e d u s i n g c o m p r e s s e d c o l u m n f o r m a t ( C C S ) t h e n t h e o u t e r l o o p w o u l d

    r u n o v e r t h e c o l u m n i n d e x ( F i g u r e 3 ) . O u r c o m p i l e r g e n e r a t e s t h e a p p r o p r i a t e c o d e b a s e d o n t h e

    f a c t t h a t w e c a n e c i e n t l y ( i n O ( 1 ) t i m e ) s e a r c h t h e m a t r i x A f o r t h e r o w i i n t h e c a s e o f C R S

    f o r m a t o r f o r t h e c o l u m n j i n t h e c a s e o f C C S f o r m a t , a n d t h a t t h e ( d e n s e ) v e c t o r s c a n b e q u i c k l y

    s e a r c h e d .

    U n l i k e p r e v i o u s w o r k ( 2 ] ) , o u r c o m p i l e r d o e s n o t h a v e t h e C R S o r C C S f o r m a t s \ h a r d - w i r e d " .

    I t r e a s o n s a b o u t t h e m b a s e d o n a h i g h - l e v e l d e s c r i p t i o n , w h i c h c o n s i s t s o f :

    D e s c r i p t i o n o f t h e h i e r a r c h y o f t h e i n d i c e s . T h i s d i e r e n t i a t e s b e t w e e n c o m p r e s s e d r o w a n d

    c o m p r e s s e d c o l u m n s t o r a g e . A l l o t h e r t h i n g s b e i n g e q u a l , w e p r e f e r t o e n u m e r a t e r o w s b e f o r e

    c o l u m n s i n t h e f o r m e r c a s e , a n d c o l u m n s b e f o r e r o w s i n t h e l a t t e r .

    D e s c r i p t i o n o f h o w e c i e n t l y t h e d a t a s t r u c t u r e c a n b e s e a r c h e d o r e n u m e r a t e d . S u p p o s e t h a t

    t h e m a t r i x A i n t h e e x a m p l e a b o v e c o n t a i n e d r o w s w i t h a l l e l e m e n t s b e i n g z e r o . W e c o u l d

    s t i l l s t o r e i t i n t h e \ u s u a l " C R S { t h a t i s s t o r e a l l n r o w s . O r w e c o u l d s t o r e o n l y n o n - z e r o

    r o w s ( w e c a n c a l l t h i s \ C o m p r e s s e d C o m p r e s s e d R o w S t o r a g e " o r C C R S ) . T h i s w o u l d s a v e

    s p a c e , b u t r e q u i r e m o r e e x p e n s i v e s e a r c h e s .

    D e s c r i p t i o n o f t h e p r o p e r t i e s o f t h e d o m a i n s o f i n d i c e s . F o r e x a m p l e , i n C R S t h e r o w i n d e x i s

    d e n s e { a l l v a l u e s f r o m 1 t o n a r e p r e s e n t . I n C C R S t h e r o w i n d e x i s s p a r s e .

    W e n o w f o r m a l i z e t h e s e i d e a s .

    2 . 2 H i e r a r c h y o f I n d i c e s

    A s s u m e t h a t t h e m a t r i x i s a r e l a t i o n w i t h t h r e e e l d s n a m e d I , J a n d V w h e r e t h e I e l d c o r r e s p o n d s

    t o r o w s , t h e J e l d c o r r e s p o n d s t o c o l u m n s a n d t h e V e l d i s t h e v a l u e . T a b l e 1 i l l u s t r a t e s

    s p e c i c a t i o n o f t h e h i e r a r c h y o f i n d i c e s f o r a v a r i e t y o f f o r m a t s .

  • 8/11/2019 Compiling P Arallel Sparse Co de for UserDefined Data

    4/9

    4

    N a m e T y p e

    C R S T

    C R S

    = I J V

    C C S T

    C R C

    = J I V

    C O O R D I N A T E T

    c o o r d

    = ( I J ) V

    D E N S E T

    d e n s e

    = I J V

    I N O D E T

    i ; n o d e

    = I N O D E

    6\

    ( I J ) V

    E L E M E N T T

    F E

    = E

    +

    ( I J ) V

    P E R M U T A T I O N T

    p e r m

    = ( I I

    0

    )

    S

    ( I

    0

    I )

    T a b l e 1

    H i e r a r c h y o f i n d i c e s f o r v a r i o u s f o r m a t s

    I n t h i s n o t a t i o n t h e o p e r a t o r i s u s e d t o i n d i c a t e t h e n e s t i n g o f t h e e l d s w i t h i n t h e s t r u c t u r e .

    F o r e x a m p l e , I J V i n t h e C o m p r e s s e d R o w S t o r a g e ( C R S ) f o r m a t 7 ] i n d i c a t e s t h a t w e h a v e

    t o a c c e s s a p a r t i c u l a r r o w b e f o r e w e c a n e n u m e r a t e t h e c o l u m n i n d i c e s a n d v a l u e s a n d t h a t w i t h i n

    a r o w , w e c a n s e a r c h o n t h e c o l u m n i n d e x t o n d a p a r t i c u l a r v a l u e . T h e n o t a t i o n ( I J ) i n t h e

    s p e c i c a t i o n o f t h e c o o r d i n a t e s t o r a g e i n d i c a t e s t h a t t h e m a t r i x i s s t o r e d a s a \ a t " c o l l e c t i o n o f

    t u p l e s .

    T h e o p e r a t o r i n d i c a t e s t h a t t h e i n d i c e s c a n b e e n u m e r a t e d i n d e p e n d e n t l y , a s i n t h e d e n s e

    s t o r a g e f o r m a t .

    ba

    1 3 42

    12

    34

    A

    c dg

    jeh

    fi

    12

    1 3

    a bc d

    34

    41 2

    h

    e

    if

    j

    g

    1

    2

    INODE

    F i g . 4 . I - n o d e s t o r a g e f o r m a t

    C o n s i d e r t h e i - n o d e s t o r a g e f o r m a t s h o w n i n F i g u r e 4 . T h i s f o r m a t i s u s e d i n t h e B l o c k S o l v e

    l i b r a r y ( 3 ] ) . I t e x p l o i t s t h e f a c t t h a t i n m a n y p h y s i c a l s i m u l a t i o n s , t h e r e a r e m a n y r o w s o f a s p a r s e

    m a t r i x w i t h t h e s a m e n o n - z e r o s t r u c t u r e

    1

    . E a c h s e t o f r o w s w i t h i d e n t i c a l s t r u c t u r e i s c a l l e d a n

    i n o d e . T h e n o n - z e r o v a l u e s i n t h e r o w s o f a n i n o d e c a n b e s t o r e d a s d e n s e m a t r i c e s , a n d t h e r o w

    a n d c o l u m n i n d i c e s a r e s t o r e d j u s t o n c e . H o w d o w e s p e c i f y s u c h f o r m a t ? T h e p r o b l e m h e r e i s t h a t

    a n e w I N O D E e l d i s i n t r o d u c e d i n a d d i t i o n t o t h e r o w a n d c o l u m n e l d s . F i e l d s l i k e i n o d e n u m b e r

    w h i c h a r e n o t p r e s e n t i n t h e d e n s e a r r a y a r e c a l l e d e x t e r n a l e l d s . A n i m p o r t a n t p r o p e r t y t h a t w e

    n e e d t o c o n v e y i s t h a t i n o d e s p a r t i t i o n t h e m a t r i x i n t o d i s j o i n t p i e c e s . W e d e n o t e i t b y t h e 6\ s y m b o l

    s u b s c r i p t i n T

    i ; n o d e

    . T h i s w i l l d i e r e n t i a t e t h e i - n o d e s t o r a g e f o r m a t f r o m t h e f o r m a t o f t e n u s e d i n

    F i n i t e E l e m e n t a n a l y s i s 8 ] . I n t h i s f o r m a t t h e m a t r i x i s r e p r e s e n t e d a s a s u m o f e l e m e n t m a t r i c e s .

    T h e e l e m e n t m a t r i c e s a r e s t o r e d j u s t l i k e t h e i n o d e s , a n d t h e o v e r a l l t y p e f o r t h i s f o r m a t i s T

    F E

    i n

    T a b l e 1 , w h e r e E i s t h e e l d o f e l e m e n t n u m b e r s . O u r c o m p i l e r i s a b l e t o r e c o g n i z e t h e c a s e s w h e n

    t h e m a t r i x i s u s e d i n a d d i t i v e f a s h i o n a n d d o e s n o t h a v e t o b e e x p l i c i t l y c o n s t r u c t e d .

    S o m e f o r m a t s c a n b e s e e n a s p r o v i d i n g s e v e r a l a l t e r n a t i v e i n d e x h i e r a r c h i e s . S u p p o s e w e h a v e a

    p e r m u t a t i o n r e l a t i o n P ( i i

    0

    ) w h i c h i s s t o r e d u s i n g t w o i n t e g e r a r r a y s : P E R M a n d I N V P . i

    0

    = P E R M ( i )

    i s t h e v a l u e o f t h e p e r m u t e d i n d e x . I N V P ( i

    0

    ) p r o v i d e s t h e i n v e r s e o f t h e p e r m u t a t i o n . T h e i n d e x

    h i e r a r c h y f o r s u c h f o r m a t i s s h o w n i n t h e t a b l e .

    1

    E a c h r o w h a s d i e r e n t v a l u e s o f c o u r s e .

  • 8/11/2019 Compiling P Arallel Sparse Co de for UserDefined Data

    5/9

    5

    B e l o w i s t h e g r a m m a r f o r b u i l d i n g i n d e x h i e r a r c h y s p e c i c a t i o n s :

    T : = V

    ?

    ?

    ?

    F

    ?

    ?

    ?

    F

    o p

    T

    ?

    ?

    ?

    F F F : : : T

    ?

    ?

    ?

    ( F F F : : : ) T

    ?

    ?

    ?

    T

    T ( 3 )

    w h e r e t h e t e r m i n a l V i n d i c a t e s a n a r r a y v a l u e e l d , a n d F i n d i c a t e s a n a r r a y i n d e x e l d .

    2 . 3 A c c e s s M e t h o d s

    A c c e s s m e t h o d s d e s c r i b e h o w t h e i n d i c e s c a n b e s e a r c h e d a n d e n u m e r a t e d f o r e a c h t e r m i n t h e

    h i e r a r c h y : F = P T . L e t P b e a p r o d u c t t y p e P = ( I

    1

    : : : I

    n

    ) . T h e n t h e f o l l o w i n g m e t h o d s

    s h o u l d b e p r o v i d e d b y a n i m p l e m e n t a t i o n :

    h b h

    k

    i = S e a r c h ( x

    k

    )

    f h x

    k

    h

    k

    i g = E n u m ( )

    t = D e r e f ( h h

    1

    : : : h

    n

    i )

    w h e r e x

    k

    i s t h e v a l u e o f t h e i n d e x o f t y p e I

    k

    , b i s a b o o l e a n a g i n d i c a t i n g w h e t h e r t h e v a l u e

    w a s f o u n d o r n o t a n d h

    k

    i s t h e h a n d l e u s e d t o d e r e f e r e n c e t h e r e s u l t , w h i c h c a n c o n c e p t u a l l y b e a

    r e l a t i o n , a s w e l l . U s u a l l y , t h e h a n d l e i s a n i n t e g e r o s e t i n t o a n u n d e r l y i n g a r r a y o r a p o i n t e r .

    N o t i c e t h a t w e c a n s e p a r a t e l y s e a r c h a n d e n u m e r a t e t h e c o m p o n e n t s o f t h e p r o d u c t t e r m . F o r

    e x a m p l e , a n i m p l e m e n t a t i o n o f t h e i - n o d e s t o r a g e w o u l d p r o v i d e a w a y t o e n u m e r a t e a l l c o l u m n

    i n d i c e s a n d a l l r o w i n d i c e s . A l s o n o t i c e t h a t t h e E n u m ( ) m e t h o d r e t u r n s a s e t o f t u p l e s .

    I f P i s o f t u p l e t y p e P = ( I

    1

    : : : I

    n

    ) t h e n o n l y o n e s e t o f f u n c t i o n s n e e d b e p r o v i d e d :

    h b h i = S e a r c h ( x

    1

    : : : x

    n

    )

    f h x

    1

    : : : x

    n

    h i g = E n u m ( )

    t = D e r e f ( h )

    2 . 4 P r o p e r t i e s o f I n d i c e s a n d A c c e s s M e t h o d s

    N o t i c e t h a t d e n s e f o r m a t a n d f o r m a t f o r i n d i v i d u a l i - n o d e s h a v e t h e s a m e h i e r a r c h y I J . O n e

    d i e r e n c e t h a t w e n e e d t o c a p t u r e i s t h a t s e a r c h e s i n t o a d e n s e m a t r i x a r e c h e a p e r . A l s o , a d e n s e

    m a t r i x s t o r e s a l l ( i j ) p a i r s w i t h i n t h e ( 1 : : : n ) ( 1 : : : n ) s q u a r e : w e k n o w t h a t f o r a c e r t a i n r a n g e

    o f t h e i n d i c e s t h e S e a r c h ( ) a l w a y s s u c c e e d s . W e a l s o n e e d t o k n o w w h e t h e r t h e i n d i c e s c a n b e

    e n u m e r a t e d i n a p a r t i c u l a r o r d e r . T h i s i s u s e d , f o r e x a m p l e , i n d e c i d i n g w h i c h j o i n m e t h o d t o

    a p p l y : m e r g e j o i n ( 9 ] ) r e q u i r e s i n d i c e s t o b e s o r t e d . I n o r d e r t o e n a b l e c e r t a i n o p t i m i z a t i o n s , w e

    n e e d t o k n o w t h e t y p e s o f t h e h a n d l e s . I n p a r t i c u l a r , w e n e e d t o k n o w i f t h e h a n d l e s l l a p a r t i c u l a r

    r a n g e o f i n t e g e r s . W e a l s o n e e d t o r e c o g n i z e t h e c a s e w h e n a c a l l t o D e r e f ( ) i s j u s t a n a r r a y a c c e s s .

    O v e r a l l , t h e f o l l o w i n g c h a r a c t e r i s t i c s o f t h e i n d i c e s a n d a c c e s s m e t h o d s a r e r e q u i r e d b y t h e

    c o m p i l e r :

    C o s t o f s e a r c h i n g : W e d i e r e n t i a t e b e t w e e n O ( 1 ) l o o k u p s , O ( l o g n ) b i n a r y s e a r c h e s a n d O ( n )

    l i n e a r s e a r c h e s .

    O r d e r i n g o f i n d i c e s : O r d e r e d o r U n o r d e r e d

    R a n g e o f t h e i n d i c e s : D e n s e o r S p a r s e . N o t i c e t h a t O ( 1 ) l o o k u p d o e s n o t n e c e s s a r i l y i m p l y

    t h a t a n i n d e x i s d e n s e : a s p a r s e a r r a y c a n b e s t o r e d u s i n g a h a s h t a b l e .

    T y p e a n d r a n g e o f h a n d l e s : W e d i e r e n t i a t e b e t w e e n a r a n g e o f i n t e g e r s a n d a g e n e r a l

    \ p o i n t e r " .

    A r i t y o f d e r e f e r e n c e : W e d i e r e n t i a t e b e t w e e n t h e r e s u l t b e i n g a s i n g l e t o n o r a r e l a t i o n .

    K i n d o f d e r e f e r e n c e : W e d i e r e n t i a t e b e t w e e n a \ g e n e r a l c a s e " a n d t h e c a s e w h e n D e r e f ( ) i s

    o n l y a n a r r a y a c c e s s .

  • 8/11/2019 Compiling P Arallel Sparse Co de for UserDefined Data

    6/9

    6

    2 . 5 S u m m a r y

    T o s u m m a r i z e t h e d i s c u s s i o n s o f a r :

    E a c h f o r m a t i s r e p r e s e n t e d b y i t s i n d e x h i e r a r c h y .

    A c c e s s m e t h o d s a r e p r o v i d e d f o r e a c h l e v e l i n t h e h i e r a r c h y .

    A c c e s s m e t h o d s a n d i n d i c e s a r e c h a r a c t e r i z e d b y t h e c o s t o f s e a r c h i n g a n d b y t h e p r o p e r t i e s

    o f t h e i n d e x a n d h a n d l e d o m a i n s .

    W e n o w u s e a n e x a m p l e t o i l l u s t r a t e h o w t h i s p r o t o c o l i s u s e d i n o p t i m i z a t i o n s .

    2 . 6 A n E x t e n d e d E x a m p l e

    L e t u s c o n s i d e r s p a r s e m a t r i x - v e c t o r p r o d u c t w h e n t h e i - n o d e f o r m a t ( F i g u r e 4 ) i s u s e d t o s t o r e t h e

    m a t r i x . T h e j o i n s c h e d u l e r a n d j o i n i m p l e m e n t e r ( d e s c r i b e d i n 5 ] ) p r o d u c e a n u n o p t i m i z e d p l a n

    D O h i n h

    i n

    i 2 E n u m ( A )

    R

    i n o d e

    = D e r e f ( A h

    i n

    )

    D O h i h

    i

    i 2 E n u m

    i

    ( R

    i n o d e

    i n )

    D O h j h

    j

    i 2 E n u m

    j

    ( R

    i n o d e

    i n )

    v

    A

    = D e r e f ( R

    i n o d e

    h h

    i

    h

    j

    i )

    v

    x

    = D e r e f ( X S e a r c h ( X j ) )

    v

    y

    = D e r e f ( Y S e a r c h ( Y i ) )

    v

    y

    = v

    y

    + v

    A

    v

    x

    F i g . 5 . U n o p t i m i z e d p l a n f o r t h e i - n o d e s t o r a g e

    f o r t h i s c o m p u t a t i o n s h o w n i n F i g u r e 5 . A n i m p o r t a n t o p t i m i z a t i o n , w h i c h i s p e r f o r m e d i n t h e

    B l o c k S o l v e p a c k a g e , i s t o g a t h e r t h e v a l u e s o f X u s e d i n e a c h i - n o d e i n t o a d e n s e v e c t o r . T h i s w a y

    t h e c o m p u t a t i o n i n t h e i n n e r l o o p s b e c o m e s a d e n s e m a t r i x - v e c t o r m u l t i p l i c a t i o n a n d c a n b e d o n e

    v e r y e c i e n t l y . H o w d o e s o u r f r a m e w o r k f a c i l i t a t e t h i s o p t i m i z a t i o n ?

    W e k n o w f r o m t h e d e s c r i p t i o n o f t h e a c c e s s m e t h o d s t h a t f o r e a c h i - n o d e t h e h a n d l e h

    x

    t a k e s

    o n a r a n g e o f i n t e g r a l v a l u e s , s a y 1 : : : M

    i n

    . T h i s a l l o w s u s t o r e p l a c e t h e f r a g m e n t i n F i g u r e 6 b y

    t h e f r a g m e n t i n F i g u r e 7 . T h e r s t l o o p g a t h e r s t h e v a l u e s o f X a n d t h e s e c o n d l o o p i s t h e c o p y o f

    t h e o r i g i n a l c o m p u t a t i o n w i t h t h e u s e o f v

    x

    r e p l a c e d b y t h e r e f e r e n c e t o t h e t e m p o r a r y a r r a y . T h e

    c o d e f o r s c a t t e r i n g X i f i t w e r e a s s i g n e d t o i n t h e o r i g i n a l l o o p i s s i m i l a r .

    D O h j h

    j

    i 2 E n u m

    j

    ( R

    i n o d e

    i n )

    v

    x

    = D e r e f ( X S e a r c h ( X j ) )

    : : : v

    x

    : : :

    E N D D O

    F i g . 6 . B e f o r e g a t h e r o p t i m i z a t i o n

    I n o u r e x a m p l e , w e c a n g a t h e r X a n d s c a t t e r Y t o o b t a i n t h e o p t i m i z e d p l a n i n F i g u r e 8 . S i n c e

    w e k n o w t h a t t h e d e r e f e r e n c e i n t o a n i n o d e b y h h

    i

    h

    j

    i i s a s i m p l e d e n s e a r r a y a c c e s s , w e c a n a c t u a l l y

    p a t t e r n m a t c h t h i s f r a g m e n t a n d c a l l t h e b e s t m a t r i x - v e c t o r m u l t i p l i c a t i o n r o u t i n e a v a i l a b l e .

    3 C o d e G e n e r a t i o n

    H o w d o e s t h e c o m p i l e r t r a n s l a t e t h e o u t p u t o f t h e O p t i m i z e r p h a s e { t h e p l a n { i n t o C o r F o r t r a n

    c o d e ? I n p a r t i c u l a r , h o w a r e t h e c a l l s t o S e a r c h / E n u m e r a t e / D e r e f e r e n c e a c c e s s m e t h o d s a r e

    t r a n s l a t e d ? T h e s i m p l e s t s o l u t i o n w o u l d b e t o w r i t e a r u n - t i m e l i b r a r y o f f o r e a c h d a t a s t r u c t u r e

  • 8/11/2019 Compiling P Arallel Sparse Co de for UserDefined Data

    7/9

    7

    A l l o c a t e r e a l a r r a y t m p ( 1 : M

    i n

    )

    D O h j h

    j

    i 2 E n u m

    j

    ( R

    i n o d e

    i n )

    t m p ( h

    j

    ) = D e r e f ( X S e a r c h ( X j ) )

    E N D D O

    D O h

    j

    = 1 M

    i n

    : : : t m p ( h

    j

    ) : : :

    E N D D O

    F i g . 7 . A f t e r g a t h e r o p t i m i z a t i o n

    D O h i n h

    i n

    i 2 E n u m ( A )

    R

    i n o d e

    = D e r e f ( A h

    i n

    )

    A l l o c a t e t m p

    x

    ( 1 : M

    j

    i n

    ) t o g a t h e r X

    A l l o c a t e t m p

    y

    ( 1 : M

    i

    i n

    ) t o s c a t t e r Y

    D O h j h

    j

    i 2 E n u m

    j

    ( R

    i n o d e

    i n )

    t m p

    x

    ( h

    j

    ) = D e r e f ( X S e a r c h ( X j ) )

    E N D D O

    D O h

    i

    = 1 M

    i

    i n

    D O h

    j

    = 1 M

    j

    i n

    t m p

    y

    ( h

    i

    ) = t m p

    y

    ( h

    i

    ) + D e r e f ( R

    i n o d e

    h h

    i

    h

    j

    i ) t m p

    x

    ( h

    j

    )

    E N D D O

    E N D D O

    D O h i h

    i

    i 2 E n u m

    i

    ( R

    i n o d e

    i n )

    D e r e f ( Y S e a r c h ( Y i ) ) = t m p

    y

    ( h

    i

    )

    E N D D O

    E N D D O

    F i g . 8 . O p t i m i z e d p l a n f o r t h e s i m p l i e d B l o c k S o l v e f o r m a t

    a n d t h e n t r a n s l a t e t h e c a l l s t o a c c e s s m e t h o d s i n t o a c t u a l f u n c t i o n c a l l s . T h e o n l y c o m p l i c a t i o n i s

    t h a t o n e c a l l t o t h e E n u m ( ) m e t h o d h a s t o b e t r a n s l a t e d i n t o t h r e e f u n c t i o n c a l l s : t o o p e n t h e s t r e a m

    o f t u p l e s , t o a d v a n c e t h e s t r e a m a n d t o c h e c k f o r t h e e n d o f s t r e a m .

    T h e p r o b l e m w i t h t h i s s o l u t i o n i s t h a t w e w o u l d h a v e t o r e l y o n t h e a b i l i t y o f t h e u n d e r l y i n g

    C o r F o r t r a n c o m p i l e r t o i n l i n e t h e s e f u n c t i o n c a l l s , b e c a u s e f u n c t i o n c a l l o v e r h e a d i s u n a c c e p t a b l e .

    I n o u r a p p r o a c h , e a c h a c c e s s m e t h o d i s a m a c r o , w h i c h i s t h e n e x p a n d e d b y t h e c o m p i l e r i n t o t h e

    a c t u a l c o d e .

    W e i l l u s t r a t e t h i s o n a n e x a m p l e . C o n s i d e r a s p a r s e m a t r i x s t o r e d i n C C S f o r m a t u s i n g t h r e e

    a r r a y s : C O L P , V A L S a n d R O W I N D . T h e a r r a y s e c t i o n V A L S ( C O L P ( j ) : : : ( C O L P ( j + 1 ) ; 1 ) ) s t o r e s t h e

    n o n - z e r o v a l u e s o f t h e j - t h c o l u m n a n d t h e a r r a y s e c t i o n R O W I N D ( C O L P ( j ) : : : ( C O L P ( j + 1 ) ; 1 ) ) s t o r e s

    t h e r o w i n d i c e s o f t h e n o n - z e r o e l e m e n t s o f t h e j - t h c o l u m n . T h e m a c r o s f o r t h e e n u m e r a t i o n o f r o w

    i n d i c e s w i t h i n a c o l u m n a n d f o r t h e d e r e f e r e n c e o f t h e v a l u e s w o u l d e x p a n d t h e f o l l o w i n g f r a g m e n t

    o f a p l a n :

    j = : : : :

    R

    c o l u m n

    = D e r e f ( A S e a r c h ( A j ) )

    D O h i h i 2 E n u m

    i

    ( R

    c o l u m n

    )

    : : : i : : :

    v

    A

    = D e r e f ( R

    c o l u m n

    h )

    : : : v

    A

    : : :

    i n t o t h e a c t u a l F o r t r a n c o d e :

  • 8/11/2019 Compiling P Arallel Sparse Co de for UserDefined Data

    8/9

  • 8/11/2019 Compiling P Arallel Sparse Co de for UserDefined Data

    9/9

    9

    p a g e d t r a n s l a t i o n t a b l e ( 1 1 ] ) . W e c a n w r i t e t h i s s c h e m e a s :

    ( i p i

    0

    ) =

    i p i

    0

    q

    0

    ( i q i

    0 0

    ) . /

    ( q )

    ( i

    0 0

    q i

    0

    )

    !

    ( 6 )

    T h e f r a g m e n t a t i o n r e l a t i o n

    0

    d e s c r i b e s t h e p a g e d ( b l o c k e d ) p a r t i t i o n i n g o f t h e r e l a t i o n :

    0

    ( i q i

    0 0

    ) q = i = B i

    0 0

    = i m o d B .

    B y v i e w i n g d i s t r i b u t i o n s a s ( g l o b a l l y d i s t r i b u t e d ) r e l a t i o n s , w e c a n r e p r e s e n t m a n y d i e r e n t

    d i s t r i b u t i o n f o r m a t s . H o w i s t h i s d i e r e n t f r o m t h e a l i g n m e n t / d i s t r i b u t i o n s p e c i c a t i o n o f H P F ?

    F i r s t o f a l l , H P F c o m p i l e r s h a v e a c e r t a i n s e t o f d i s t r i b u t i o n f o r m a t s \ h a r d - w i r e d " . S e c o n d ,

    a l i g n m e n t / d i s t r i b u t i o n s p e c i c a t i o n i n H P F o n l y s p e c i e s a m a p f r o m g l o b a l i n d e x t o p r o c e s s o r

    n u m b e r . A p a r t i c u l a r l o c a l s t o r a g e f o r m a t ( a n d t h e r e l a t i o n s h i p w i t h t h e l o c a l i n d e x ) i s i m p l i c i t i n

    t h i s s c h e m e . T h i s s i m p l i e s t h e j o b o f a u s e r , b u t i s l e s s e x i b l e i n i n t e r f a c i n g o t h e r c o d e s ( s u c h a s

    d i s c r e t i z a t i o n a n d p a r t i t i o n i n g s y s t e m s ) .

    C u r r e n t r e s e a r c h c o m p i l e r s h a v e d i e r e n t c o m p i l a t i o n p a t h s f o r r e g u l a r a n d i r r e g u l a r d i s t r i b u -

    t i o n s ( 1 0 ] ) . W e b e l i e v e t h a t o u r S P M D t r a n s l a t i o n a l g o r i t h m c a n b e u s e d a s a p a s s i n a n H P F

    c o m p i l e r a f t e r t h e c o m p i l e r h a s g e n e r a t e d t h e s p e c i c a t i o n f o r l o c a l s t o r a g e . T h i s w a y r e g u l a r a n d

    i r r e g u l a r d i s t r i b u t i o n s c a n b e h a n d l e d u n i f o r m l y .

    5 C o n c l u s i o n s a n d F u t u r e W o r k

    W e h a v e s h o w n h o w v a r i o u s s p a r s e m a t r i x a n d d i s t r i b u t i o n f o r m a t s c a n b e h a n d l e d u s i n g t h e

    r e l a t i o n a l a p p r o a c h t o s p a r s e m a t r i x c o d e c o m p i l a t i o n . C u r r e n t l y , o u r t e c h n i q u e s a r e o n l y a p p l i c a b l e

    t o D O A L L l o o p s a n d l o o p s w i t h r e d u c t i o n s : t h e c o m p i l e r o n l y n e e d s t o n d t h e b e s t w a y t o

    e n u m e r a t e o v e r t h e d a t a s t r u c t u r e s w i t h o u t w o r r y i n g a b o u t t h e l e g a l i t y o f s u c h e n u m e r a t i o n . W e

    h a v e e x t e n d e d t h e s e t e c h n i q u e s t o l o o p w i t h d e p e n d e n c i e s f o r a r e s t r i c t e d c a s e o f C o m p r e s s e d

    H y p e r p l a n e S t o r a g e ( 4 ] ) , a n d w e a r e c u r r e n t l y w o r k i n g o n g e n e r a t i n g c o d e w i t h d e p e n d e n c i e s f o r a

    w i d e r r a n g e o f d a t a s t r u c t u r e s .

    R e f e r e n c e s

    1 ] C . A n c o u r t , F . C o e l h o , F . I r i g o i n , a n d R . K e r y e l l , A l i n e a r a l g e b r a f r a m e w o r k f o r s t a t i c h p f c o d e

    d i s t r i b u t i o n , i n C P C ' 9 3 , N o v e m b e r 1 9 9 3 . A l s o a v a i l a b l e a t h t t p : / / c r i . e n s m p . f r / d o c / A - 2 5 0 . p s . Z .

    2 ] A . B i k , C o m p i l e r S u p p o r t f o r S p a r s e M a t r i x C o m p u t a t i o n s , P h D t h e s i s , L e i d e n U n i v e r s i t y , t h e

    N e t h e r l a n d s , M a y 1 9 9 6 .

    3 ] M . T . J o n e s a n d P . E . P l a s s m a n n , B l o c k S o l v e 9 5 u s e r s m a n u a l : S c a l a b l e l i b r a r y s o f t w a r e f o r t h e p a r a l l e l

    s o l u t i o n o f s p a r s e l i n e a r s y s t e m s , T e c h . R e p . A N L { 9 5 / 4 8 , A r g o n n e N a t i o n a l L a b o r a t o r y , D e c . 1 9 9 5 .

    4 ] V . K o t l y a r a n d K . P i n g a l i , S p a r s e c o d e g e n e r a t i o n f o r i m p e r f e c t l y n e s t e d l o o p s w i t h d e p e n d e n c i e s , i n

    A C M I C S ' 9 7 , J u l y 1 9 9 7 .

    5 ] V . K o t l y a r , K . P i n g a l i , a n d P . S t o d g h i l l , A r e l a t i o n a l a p p r o a c h t o s p a r s e m a t r i x c o m p i l a t i o n , i n

    E u r o P a r , A u g u s t 1 9 9 7 . A v a i l a b l e a s C o r n e l l C o m p u t e r S c i e n c e T e c h . R e p o r t 9 7 { 1 6 2 7 ( h t t p : / / c s -

    t r . c s . c o r n e l l . e d u ) .

    6 ] , U n i e d f r a m e w o r k f o r s p a r s e a n d d e n s e s p m d c o d e g e n e r a t i o n ( p r e l i m i n a r y r e p o r t ) . , T e c h . R e p .

    T R 9 7 - 1 6 2 5 , C o m p u t e r S c i e n c e D e p a r t m e n t , C o r n e l l U n i v e r s i t y , 1 9 9 7 . h t t p : / / c s - t r . c s . c o r n e l l . e d u .

    7 ] S . P i s s a n e t z k y , S p a r s e M a t r i x T e c h n o l o g y , A c a d e m i c P r e s s , L o n d o n , 1 9 8 4 .

    8 ] G . S t r a n g , I n t r o d u c t i o n t o a p p l i e d m a t h e m a t i c s , W e l l e s l e y - C a m b r i d g e P r e s s , 1 9 8 6 .

    9 ] J . D . U l l m a n , P r i n c i p l e s o f D a t a b a s e a n d K n o w l e d g e - B a s e S y s t e m s , v . I a n d I I , C o m p u t e r S c i e n c e

    P r e s s , 1 9 8 8 .

    1 0 ] R . v . H a n x l e d e n , K . K e n n e d y , a n d J . S a l t z , V a l u e - b a s e d d i s t r i b u t i o n s a n d a l i g n m e n t s i n F o r t r a n

    D , T e c h . R e p . C R P C - T R 9 3 3 6 5 - S , C e n t e r f o r R e s e a r c h o n P a r a l l e l C o m p u t a t i o n , R i c e U n i v e r s i t y ,

    D e c e m b e r 1 9 9 3 .

    1 1 ] J . W u , R . D a s , J . S a l t z , H . B e r r y m a n , a n d S . H i r a n a n d a n i , D i s t r i b u t e d m e m o r y c o m p i l e r d e -

    s i g n f o r s p a r s e p r o b l e m s , I E E E T r a n s a c t i o n s o n C o m p u t e r s , 4 4 ( 1 9 9 5 ) . A l s o a v a i l a b l e f r o m

    f t p : / / h y e n a . c s . u m d . e d u / p u b / p a p e r s / i e e e t o c . p s . Z .