Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. multithread

multithread

Scheduled Pinned Locked Moved Managed C++/CLI
data-structurestutorialquestion
4 Posts 3 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13028254
    wrote on last edited by
    #1

    how to make a program multithread to find a max number in array?? sample code please..

    J M 2 Replies Last reply
    0
    • U User 13028254

      how to make a program multithread to find a max number in array?? sample code please..

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      Sample code can be found in the web. We are going to help if you have already tried something and got stuck. But we will not write the code for you. But there is a simple approach: Write a function that calculates the max. for a passed range (start pointer and number of items) and stores the maximum value in another array. Create a number of threads that calls that function passing sub ranges of your array. When all threads has finished call the function again passing the array containing the results. An alternative solution would not use an additional array but a shared variable to hold the maxmimum value found so far. But then the threads must use locking which is probably not very efficient.

      U 1 Reply Last reply
      0
      • J Jochen Arndt

        Sample code can be found in the web. We are going to help if you have already tried something and got stuck. But we will not write the code for you. But there is a simple approach: Write a function that calculates the max. for a passed range (start pointer and number of items) and stores the maximum value in another array. Create a number of threads that calls that function passing sub ranges of your array. When all threads has finished call the function again passing the array containing the results. An alternative solution would not use an additional array but a shared variable to hold the maxmimum value found so far. But then the threads must use locking which is probably not very efficient.

        U Offline
        U Offline
        User 13028254
        wrote on last edited by
        #3

        thank you.

        1 Reply Last reply
        0
        • U User 13028254

          how to make a program multithread to find a max number in array?? sample code please..

          M Offline
          M Offline
          Munchies_Matt
          wrote on last edited by
          #4

          #define D define
          #D Y return
          #D R for
          #D e while
          #D I printf
          #D l int
          #D W if
          #D C y=v+111;H(x,v)*y++= *x
          #D H(a,b)R(a=b+11;au){R(w=i=0;i<4;i++)w+=(m=v[h[i]])==f?300:m==q?-300:(t=v[ih[i]])==f?-50:
          t==q?50:0;Y w;}H(z,0){W(E(v,z,f,100)){c++;w= -S(d+1,n,q,0,-b,-j);W(w>j){g=bz=z;
          j=w;W(w>=b||w>=8003)Y w;}}}W(!c){g=0;W(_){H(x,v)c+= *x==f?1:*x==3-f?-1:0;Y c>0?
          8000+c:c-8000;}C;j= -S(d+1,n,q,1,-b,-j);}bz=g;Y d>=u-1?j+(c<<3):j;}main(){R(;t<
          1600;t+=100)R(m=0;m<100;m++)V[t+m]=m<11||m>88||(m+1)%10<2?3:0;I("Level:");V[44]
          =V[55]=1;V[45]=V[54]=2;s(u);e(lv>0){Z do{I("You:");s(m);}e(!E(V,m,2,0)&&m!=99);
          W(m!=99)lv--;W(lv<15&&u<10)u+=2;U("Wait\n");I("Value:%d\n",S(0,V,1,0,-9000,9000
          ));I("move: %d\n",(lv-=E(V,bz,1,0),bz));}}E(v,z,f,o)l*v;{l*j,q=3-f,g=0,i,w,*k=v
          +z;W(*k==0)R(i=7;i>=0;i--){j=k+(w=r[i]);e(*j==q)j+=w;W(*j==f&&j-w!=k){W(!g){g=1
          ;C;}e(j!=k)*((j-=w)+o)=f;}}Y g;}

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups