⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arrayaddpartition.java

📁 collective processing environment for mobile devices. It is an environment for mobile device to solv
💻 JAVA
字号:
package com.ibm.user.examples;
import com.ibm.dthreads.DThread;
import com.ibm.dthreads.MP.ObjectMP;
import com.ibm.DataPartition.*;

public class ArrayAddPartition extends DThread {
	
	        int data[][];
			int low;
			int high;
			int id;
			int size;
			int totalThreads;
			int psum=0;
			int row;
			int col;
			
	ArrayAddPartition(int dim)
			{
				row=dim;
				col=dim;
				data=new int[row][col];
				for(int i=0;i<data.length;i++)
				{
					for(int j=0;j<data.length;j++)
					{
						data[i][j]=1;						
					}
				  
				
				}
		
			}
	
			public void run()
			{
				id=DThread.getContext().getIdentity();
				ObjectMP messagepasser= DThread.getContext().getMP();
				totalThreads=DThread.getContext().getNumberOfThreads();

                        //Does the partitioning of the 2D data array 
				Partition2D part=new PartitionInt2D(data,row,col,id,totalThreads,Config.BLOCK_ROW_MAJOR_DISTRIBUTION);
         
 	                  //Getting the partial 1D data array of this DThread   
	         		SpmdIntData2D partData=(SpmdIntData2D)part.getPartition(id);

                        //Get the sum of all the elements in the partial array
				psum=partData.sum();
				if(id==0)
				{
					long total=psum;
					messagepasser.barrier();
                              //Root gets the partial summ from all the other DThreads
					for(int i=1;i<totalThreads;i++)
					{
						long partialresult=(long)(((Integer)messagepasser.get(i,"0")).intValue());
						total+=partialresult;
					}
					System.out.println("Total Sum is "+total);
				}

				else
				{
					System.out.println("PARTIAL RESULT IS "+psum);
                              //Send the partial sum to the root
					messagepasser.put(new Integer((int)psum),id,0,"0");
					messagepasser.barrier();
				}
				
		 
			  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -