Internati o nal  Journal of Ele c trical   and Computer  Engineering  (IJE CE)  Vol .   5 ,  No . 3,  J une   2 0 1 5 ,  pp . 56 2~ 56 8   I S SN : 208 8-8 7 0 8           5 62     Jo urn a l  h o me pa ge : h ttp ://iaesjo u r na l.com/ o n lin e/ind e x.ph p / IJECE  Implementation of Cloth Simula tion Using Parallel Computing  on M o bile Device        Jae   H o n g  Jeon*,   Se Don g  Min**,   and Min  Hong***  * Department of   Computer Scien ce, Gradua te Sch ool, Soonchunh yang University Korea    ** Departmen t  o f  Medical IT En gineer ing, Soonchunh y a ng  University , Korea  *** Departmen t   of Computer Sof t ware  E ngin eering, Soonchunh yang University Korea      Article Info    A B STRAC T Article histo r y:  Received  Ja n 13, 2015  Rev i sed  Ap 20 , 20 15  Accepte May 5, 2015      Ph y s ically  based modeli ng and simulation is  an important technique for   deform able obj e c t sim u lat i on, w h ich is wide l y  u s ed to repr esent  the re alist i c   shape ch ange  an d movement of  objects  for m obile gam e  o r  3D sim u lation .   However, th ey   require the hig h  com putational cost for  representing th ph y s ical pheno menon on deformable obj ects when it applied  on mobile   device. In th is p a per, we d e sign ed  and  im plem e n ted  the  clo t h si m u lation for   deformable object simulation using the  parallel  techn i que on mobile device  to optim iz the  com putation a l b u rden. W e  espe cia l l y   appli e d G P U parall e l   techn i que for th e integr ation solving  process such as Euler ,  Midpoint, 4th- order Runge-K utta method  to  estimate  the particles '   n e xt status  using  positions and velocit i es. Also we appli e d m u lti-t h read par a ll el te chnique fo r   cal cula ting  the   s p ring force .   T h en we  com p ar ed th e perfo rm ance of  e ach  integr ation meth ods between und er onl y  CPU and  CPU with GPU on m obile  devic e .  Als o  we  com p ared th co m pu ting time of   spring calculatio n between   onl y CPU and us ing CPU m u lti-t h read. Keyword:  C l ot h si m u l a t i on   GP GP U   Mass spring sy ste m   Sha d er   Tran sf orm  feedbac k   Copyright ©  201 4 Institut e  o f   Ad vanced  Engin eer ing and S c i e nce.  All rights re se rve d Co rresp ond i ng  Autho r Min  Ho ng,    Depa rt m e nt  of  C o m put er S o ft ware  En gi nee r i n g ,   Soo n c hu nh yang  U n i v er sity,  U n it  5 0 7 ,  Mu lt i m ed ia Bld ., So on ch unh yang   U n i v ., Eu m n ae- r i Sin c h a ng-myeo n ,   A s an - s i,  C h u n g che o ng n a m - do , 33 6- 7 4 5   R e p. of   K o re Em ail: m hong@sch.ac.kr       1.   INTRODUCTION  Al t h o u gh  va ri ous m obi l e  ap pl i cat i ons  have  been i m pl em ent e wi t h  rece nt  ad vance d  m obi l e  de vi c e   t echn o l o gi es,  m o st  appl i cat ions a r e base on  2D c ont e n t s  due t o  t h e l i m i t e d perf orm a nce o f  m obi l e  devi ces .   Thu s , t h e im p l e m en tatio n  of  g a m e , an i m ati o n,  v i rtu a reality, au g m en ted  reality, an d ad v e rtisem en wh i c requ ire  realistic represen tatio n  of  3 D   ob jects is d i ffi cu lt to  im p l e m en t o n  m o b ile d e v i ces. In  ad d ition ,  the  adve nt  o f  rece nt  HM (Hea d  M o u n t e Di sp l a y )  devi ces s u ch as Oc ul us l i fe an d Gea r  V R  have  been  re cei ved   th e p u b lic att e n tio n  in   VR  (Virtu al Reality) wo rld .  Th e real ob j ect s th at h a v e  rig i d  or d e formab le   ch aracteristics fo r realistic represen tatio n o f  m o v e m e nt  and i n t e ract i on  bet w ee n o b ject hi g h l y  req u i r p h y sically-b ased  sim u latio n .     A 3D de formable object sim u la tion can  represe n t the deform ed  obje cts like real objects ,  but it  req u i r es t h hi gh  com put at i o nal  p o w er  due  to re pres ent t h e 3D  object  worl d   or related  calcu latio n .   It h a to   co m p u t e lo ts o f   ph ysically  related  calcu latio n s  in  eac h sim u lation time step, so t h e physically base si m u latio n  is  no t triv ial t o   p e rfo r m  o n  m o b ile d e v i ces.  To   s o lv e th e s e pr ob le ms ,   ma n y  r e s e a r c h es   h a v e  b een  wid e ly stu d i ed o n   n u m erical  in teg r ation  m e th od s, co llis io n  ch eck  and  resp on se m e th o d s [1 ], m u lti-co re and  paral l e l  ap pr oa ches [ 2 ]  o n  m obi l e  de vi ces.  Ho we ver m o st  researc h es  ha ve bee n  f o c u s e d o n  t h reg u l ar PC   envi ro nm ent s  not  m obi l e  e n v i ro nm ent s Evaluation Warning : The document was created with Spire.PDF for Python.
                        I S SN 2 088 -87 08  IJEC E V o l .  5, No . 3,  J u ne 2 0 1 5   :    56 2 – 5 6 8   56 3 Recent m obile de vices  provi de the  GPU that has  re latively low cl ock speed,  bu t it provides  lots  of  ALUs (Arith metic Lo g i c Un i t ) wh ich  can  be ap p lied  to  parallel p r o cessi n g . Ho wev e r, th ere are no  official   p a rallel p r o c essin g   related  lib raries  for mo b ile d e v i ces  u n til no wh i c h  can  con v e n i en tly su ppo rt th i m p l e m en tatio n  of m o b ile app licatio n .   Th GPU is si m u lt an eou s ly workin g   with   ALUs, so wh en  GPU go t   wo rk  pr ocess ,  i t  separat e s an d l a unc hes t h num ber o f  AL Us  an d pe rf or m s  t oget h er i n   sam e  t i m e . This i s  we  call GPGPU (Gene r al-Purpose com puting  on  Gra p hics Processing Units).   In t h i s  pa pe r,  we p r o p o sed a nd i m pl em ent e d t h e p h y s i cal l y  based cl ot h s i m u l a t i on [3]  u s i ng a ve rt ex   sh ad er that com p u t es lo ts o f  p a rticle po sitio n s  w ith   G P GPU  sim u ltan e ou sly.  W e   pr opo sed  a n e w  al g o r ith that using a transform  feed back [4] which  can capt u re t h e data from  a sha d er a nd ca n re use them  in ne xt   si m u latio n  ti me. Also  we  prop o s ed   n e w cloth  sim u lat i o n   d a ta stru ctu r an d  m u lti-th read  [5 ] [6 ] m e t h od   for  calcu latin g  t h e spring  fo rces. In  ad d ition ,   we  p e rform e d  th e clo t h  si m u la tio n  using   o n l y CPU  an d th pr o pose d   GP U  paral l e l  com put i ng a n d com p are d  t h per f o rm ance of  sp ri n g  cal cul a t i o n t i m e  usi ng  m u lt i - t h rea d  C P U a n onl y  C P U.       2.   CLOTH SIMULATION USIN G PARAL LEL COMPUTING  The c o m put at ion  o f  p r o p o se d cl ot h  si m u l a t i on u s i n g G P GP U m e t hod  can be  cl assi fi ed i n t o  t w o   part s:  C P U c o m put at i on an d  GP U c o m put a t i on.  The  ba si c cl ot h  si m u l a t i on  p r ope rt i e s s u ch  as  n ode s,  spri ng   co nn ection s , ex tern al forces  an d  so  on  are i n itialized  a n d   sto r ed  on  CPU. Th en  it co m p u t es all sp ring  forces  and s u m  up these force s  with external forc es at each  nodes using CPU. In ne xt  step, it co m putes the next   status of  node  positions using  GP GPU using  GPU. Al l ne xt positions of each  node are inde pe nde ntly  com put ed by  GP GP U,  s o   i t  has  t o  be  ar ra n g ed  with  s u itab l e fo rm at for  G P U a n d CP U.      2. 1 Da ta   S t ruc t ure of   Cl ot h Si mul a ti on   Data stru cture of clo t h  sim u latio n  in ou p a p e is  d i fferen t fro m  th e t r ad ition a l appro ach.  Nod e   in fo rm atio n  in  trad itio n a l clo t h  sim u latio n  in clu d e s t h e po si tio n ,   v e lo city, an d   fo rce in  each  un it. Th is syste m   sh ou l d  co n t i n uo u s ly m a n a g e  th e d a ta tran smissio n  to  send  th ese d a ta to GPU m e m o ry  in  ev ery ti m e   step . In  th e p r op o s ed  alg o rith m ,  th e p o s itio n, v e lo cit y , an d  fo rce inform at io n  are  man a g e d   with  ex actly sa m e  f o rm at   i n  G P U  m e m o ry  by  l i s t  an whe n  t h ese i n f o rm at i on are  r e qui red  t o   be c a l c ul at ed, t h ey  are  refe rre us i ng l i s t   by  p o i n t e r. T h ere f o r e,  t h pr o pose d   dat a  st ruct ur can pre v e n t the  unnecessa ry   data tran sm issi o n  for  rearrang em en t o f   po sitio n,  v e lo city, fo rce and  m a ss in  ev ery ti m e  step . Fig u re  1  sho w s th e co m p ariso n   o f   d a ta  stru cture  b e tween  th e trad itio nal clo t h  sim u latio n  an d th e pro p o s ed  cl o t h  si m u la tio n .       Evaluation Warning : The document was created with Spire.PDF for Python.
I J ECE   I S SN 208 8-8 7 0 8     Imp l emen ta tion   o f  Clo t h S i mu la tion   Using   Pa ra llel Co mpu tin g on   Mob ile Device   (Min  H ong 56 4           Fi gu re  1.  Dat a   st ruct u r e c o m p ari s o n   bet w ee n  t h e t r a d i t i onal   and  p r op ose d  c l ot h si m u l a t i on      2. 2 Cal c ul ate  of   Spri n F o r ce  usi n g Mul t i - T h rea d of   C P U   Gene ral l y , cal cul a t i on  of s p r i ng f o rce s  i n  cl ot h si m u l a ti on  req u i r es l o t s   of c o m put at i onal  t i m e  and  th e trad itio n a clo t h  sim u latio n   u s ed on ly one CPU  for  t h is com putation t h at leads t h decreased sim u lation  p e rform a n ce. To  so l v e th e p r ob lem ,  th p r op o s ed   m e th o d   u tilized  th m u lti-th read  ap pro ach  on   CPU to  calcu late th e sp ri n g   forces in p a rallel  m a n n er. Th e propo sed  algo rith m  sp lits n  spring in to  16  thread   g r ou p s   and eac h gr o u p  i nde pe nde nt l y  cal cul a t e s spri n g  fo rces wi t h  i t s  own t h re ad.  Whe n  t h e cal cul a t i on o f  spri ng   forces is fi n i shed  in  ev ery t h read , t h e proposed  algorith m   calcu lates th n e x t  status of  n o d e   p o sitio n s  u s ing  num erical integration. Si nce each spring  is connected  with two  nodes, the calculated spring forces are  store d   in ass o ciated  node i n form ation. Beca use s e veral t h rea d s  can acces s to sam e  node at  the sam e  time, we   appl i e d  t h e m u t e x (m ut ual  ex cl usi o n) t o   pre v ent  t h i s  p r obl em . Fi gu re  2 s h o w s t h fl o w chart   of  i m pl em ent e d   clo t h  sim u latio n   with  m u lti-th read of CPU an d with on e C P U.      Po s i t i o n   (Floa t *   [3])   Ve l o c i t y   (Floa t *   [3])   Fo rc e   (Floa t *   [3])   Mass   (Floa t *   )     ~   ~   ~   ~   D at   Po s i t i o n   (Floa t *   [3])   Ve l o c i t y   (Floa t *   [3])   Fo rc e   (Floa t *   [3])   Mass   (Floa t *   )     ~   ~   ~   ~   D at Evaluation Warning : The document was created with Spire.PDF for Python.
                        I S SN 2 088 -87 08  IJEC E V o l .  5, No . 3,  J u ne 2 0 1 5   :    56 2 – 5 6 8   56 5     Fig u re  2 .  Flowch art  o f  clo t h  si m u latio n  u s i n g  m u lti-th read  CPU an o n e   CPU      2. Cl o t h Si m u l a ti on  usi n g  t h e T r a n sf orm  Feedb a ck  B u ffer   The C P U pa ss es al l  no de dat a  i n t o  G P U m e m o ry , and  vert ex s h ade r  c onc ur rent l y  cal cul a t e s t h e ne xt   n o d e  po sition s  u s ing  GPGPU an d  th en  upd ated  n o d e   p o s iti o n   d a ta sho u l d b e  tran sferred to  in to  CPU.  In  th is  r e s e a r ch , w e  ap p lie d th e tr ans f or m f e e d b a ck   b u f f e r  th at i s  rece ntly suppos ed  by   o p en  GL  ES Usin g th trans f orm  feedback  buffer,  we can  cap ture th e no d e   d a ta after calcu latio n o n   GPU and  th en   p u sh  th ese d a ta  in to  th e tran sform feed b a ck  buffer. Therefore, the im pl em ent e d cl ot h si m u l a t i on wi t h  t h e t r ansf orm  feedba c k   buffe r ca n efficiently transfer the  related data fr om  GPU t o  C P U .   Fi gu re  3 sh o w s t h fl o w c h art   of  im pl em ent e d cl ot h si m u l a t i on usi n g  GP U.             Fi gu re  3.  Fl o w chart   of  t h e i m pl em ent e d cl ot h si m u l a t i on w i t h  GP U       3.   R E SU LTS AN D ANA LY SIS  Fi gu re  4 s h o w s t h e  res u l t   of e x peri m e nt al  t e st  whi c was  per f o r m e on  IPa d   Ai r  R e t i n a.  We  per f o r m e d Sem i -Eul er, M i d poi nt , 4t h - or de r R u n g e - K u t t a   m e t hod t o  co m p are t h e perf orm a nce of  G P U an d   CPU  en v i r o n m en ts  u n d e r fr om  3 , 6 0 0  to 250,00 0 v e r tices.    Evaluation Warning : The document was created with Spire.PDF for Python.
I J ECE   I S SN 208 8-8 7 0 8     Imp l emen ta tion   o f  Clo t h S i mu la tion   Using   Pa ra llel Co mpu tin g on   Mob ile Device   (Min  H ong 56 6          Fi gu re  4.   S n a p shot s  o f  i m pl em ent e d cl ot h si m u l a t i o n       As a resu lt, t h e p r op o s ed   GPU p a rallel techn i qu e wit h  the  trans f orm  feedback  buffer is  m u ch faster  t h an  onl y  C P U ,  whe n  t h nu m b er of n odes  i s  over t h e s p eci fi c brea ki n g  poi nt . Si nce c l ot h si m u l a t i on wi t h   GPU  p a rallel co m p u tin g   h a s to  tran sfer t h d a ta fro m   CPU to GPU m e m o ry, it req u i res th e tran sfer  laten c y.  Ho we ver ,   whe n  t h num ber  of  n o d es i s  o v e 6, 00 0  ve rt i ces, t h e   pr op os ed m e t hod  i s   m u ch fast er  t h an  o n l y   CPU m e thod. In a d dition, 4th-orde r R u nge - Kutta  m e thod which  requires m o re  com p lex com puting  ope rat i o ns  has  m o re adva nt ag e wi t h   GP U.  F i gu re 5  sh o w t h e pe rf orm a nc e res u l t  (m s) o f  com p ari s o n   wi t h   di ffe re nt  i n t e g r at i on m e t hods   usi n GP U a n d  C P U.           Fi gu re  5.  The   per f o r m a nce re sul t  wi t h  di f f er ent  i n t e g r at i o m e t hods  wi t h   C P U a n d  G P U       Th e propo sed   m u l ti-th read  C P U p a rallel tec h n i q u e  m e th o d  is  m u ch  faster th an  CPU on l y , wh en  th n u m b e r of spri n g s  is ov er 40 ,0 00 . Spring  force calcu latio ns can  b e  qu ickly p r o cessed  by sp littin g  th em in to  m u l ti-th read   C P U. Alth oug h  th ere  is  no si g n i f i cant  i m pro v em ent  of per f o rm ance whe n  t h e num ber of  spri n g   i s  l o w, w h en t h e n u m b er of  spri ngs i s  get t i ng i n c r ease d , t h e m u l t i - t h rea d  di vi des t h e s p ri ngs i n t o  1 6  gr o ups   an q u i ck ly calcu lates th em u s i n g m u lti-c o re in m o b ile  d e v i ce.  Th erefore, we b e liev e  t h at th e pro p o s ed  m e t hod i s   wel l  sui t a bl fo r s o m e  sim u l a t i on appl i cat i o ns t h at  req u i r pl au si bl e real -t i m per f o r m a nce o f  cl o t h   si m u latio n  fo m o b ile d e v i ces. Figu re 6 shows th e resu lt of p e rform a n ce test fo r clo t h  si m u la tio n  wh en m u lt i- th read  CPU  was app lied  t o  th e calcu latio n of  sp ri n g  fo rces.      Evaluation Warning : The document was created with Spire.PDF for Python.
                        I S SN 2 088 -87 08  IJEC E V o l .  5, No . 3,  J u ne 2 0 1 5   :    56 2 – 5 6 8   56 7     Fig u re  6 .  Th p e rform a n ce resu lt of sp ri n g  fo rc e calcu lation   u s ing  m u lti-th read  CPU and on ly CPU      4.   CO NCL USI O NS   In t h i s  pa pe r,  we p r op ose d  t h e cl ot h si m u lat i on  usi n par a l l e l  co m put i n g m e t hods t h at  are b a sed  o n   th e m u lti-th read  with  C P U and  th e tr an sform feedb a ck  bu ffer  with  GPU. Using   th tr an sform  feed b a ck   b u ffer  whi c h can ca pt ures  no de i n fo rm ati on, w h e n  shade r  i s  wo r k i n g o n  m obi l e  devi ce.  T h e m u lti-thread C P U can  d i v i d e  and  ex ecu t e th e calcu latio n   o f  spring forces  with  some o f   g r o u p s To   u p d a te th p o s ition  an d velo city   of no des, we use d   Sem i -Eul er,  M i d poi nt 4t h - o r de r Rung e-Ku tta in tegratio n  m e th o d s b a sed   on  CPU and  GP U. T h e p r o pos ed  GP U pa r a l l e l  t echni que  i s   m u ch fast er   th an  CPU,  wh en  th e nu m b er of no d e s is relativ ely  hi g h  en o u g h Al so t h e m u l t i -t hrea d C P U p a ral l e l  t echni q u e re duce s  t h spri ng  fo rce co m put i ng t i m e  in cl ot h   sim u l a t i on. I n   t h i s  pa per, al t h ou g h  we c o nfi r m e d t h e per f o r m a nce of t h C P U an GP U  paral l e l  com put i n g   app r oach , we di d n o t  com b i n e t w pr op os ed m e t hod s y e t .  The i n t e grat ed cl ot h si m u lat i on usi ng b o t h  C P U   and GPU pa ral l el processing  is exp ected t o   provide m u ch  im proved pe rf orm a nce o f  cl ot si m u l a ti on,  w h e n   th e spring   force co m p u t atio n  wit h  m u lti-t h read  CPU and  wit h  GPU  usin g  t r an sfo r m feedb a ck   b u ffer are  co m b in ed . In  ad d ition ,  real-ti m e  d e form ab le 3 D  ob j ect  si m u latio n  can b e  a g o o d  can d i d a te in   mo b ile  envi ro nm ent  t o  achi e ve  t h re al i s t i c  and  pl ausi bl pe r f o rm ance a n d  be ha vi o r  o f   de formable objects for thes e   C P U a n d  G P U   paral l e l  p r oces si ng  m e t hods.       ACKNOWLE DGE M ENTS  Th is w o rk  w a s su ppo r t ed  b y   th Soo n c hu nhyan g  Un iv er sity  Resear ch  Fun d     REFERE NC ES   [1]   J .  M o s e gaard, “ A  GP U acceler a t ed s p ring m a s s  s y s t em  for s u rgi cal s i m u la tion” Studies inHea lth  Technology and  Informatics , vo l. 111, pp. 342–34 8, 2005 [2]   J.H. Jeon, M.H. Choi, Y. S. Jeong and M. Hon g , “Hierarchical B ounding Sphere FFD-AABB  Algorithm for Fast  Collision Handi ng of 3D Deform able Objec t s o n  Sm art Devices ”,  Journal of Internet Techno log y , V o l 14 , N o . 5 ,   pp. 843-850 , 20 13.  [3]   D. Baraff and W. Andrew, “L arge  steps in cloth simulation”,  Proceedings of  the 25th annual conferen ce on  Computer graphics and  inte ra ctive techniques.  ACM , pp .43-54, 1 998.  [4]   D. Ginsburg, B .     Purnomo, D. Shreiner and A.   Munshi, “Open  GL ES 3 . 0 Progr amming Guide,” 2014.  [5]   S .  Kazuki, and T. F u rum o to. “Grand centra l  di s p atch” ,  Pro Multithread ing and Memory Manag ement for iOS a n d   OS X.  Apress , 13 9-145, 2012 [6]   V. Nahavand ipo o r, “ C oncurrent  Progr am m i ng in Mac OS X and iOS: Unleash Multicor e Perform ance wi th Grand   Central Dispatch ”, O ' Re illy   Media, In c., 2011                   Evaluation Warning : The document was created with Spire.PDF for Python.
I J ECE   I S SN 208 8-8 7 0 8     Imp l emen ta tion   o f  Clo t h S i mu la tion   Using   Pa ra llel Co mpu tin g on   Mob ile Device   (Min  H ong 56 8 BIOGRAP HI ES OF  AUTH ORS     Jae Hong Jeon  received BS d e gree  in Depar tment of Compu t er Software  En gineer ing from  Soonchunh y a ng  University   in  2012. Now he  is  undertak ing  a master d e gree of  computer   engineering  cou r se as a member of th e Com puter Graphics  Lab   at Soonchunh y a ng University His  res earch  int e res t s  ar e com p uter g a m e  deve l opm ent, com put er graph i cs , AR  (Augm ented  Reality ) and embedded  motion   capture        Se  Dong M i n  was born in Seo u l, Korea,  in 19 75. He  r e c e ived  the M . S .  and  P h .D. degr ees   in   ele c tri cal  and ele c troni c engi neering from  th e Department of Electr i cal  and Electronics   Engineering, Y onsei University , Seoul, in 2004  and 2010, respectively .  He is currently   an  Assistant Professor at the Dep a r t ment of Me dical IT  Engineerin g, Soonchunh y a ng University As an, Korea.  His  res earch ar ea inc l udes  bio m edical s i gn al  proces s i ng, he al thcar e s e ns or  application, and   mobile health car e technolog ies.        M i n Hong  is   an  As s o ciate  P r ofe s s o r at th e Depa rtm e nt of Comp uter Softwar e  an d Engineering ,   Soonchunh y a ng  University  in  Asan, Korea. He  received  BS in Comput er Scien ce fro Soonchunh y a ng  University  in  1995. He also rece ived MS in  Computer Science and PhD in  Bioinformatics from the University  of Colora do  in 2001 and 2005, respectively .  His research   inter e s t s  are in  Com puter Graphics , M obi le  Computing, Ph y s ically - b ased  Modeling and  Sim u lation, Bio i nform a tics Applic ations , and u - Health car e Applic a tions. In pr esent, he is a  Director  of Com puter Graph i cs  Laborator y   at Soo n chunh y a ng University   Evaluation Warning : The document was created with Spire.PDF for Python.