本文整理汇总了C++中Comm::getNumberOfProcessors方法的典型用法代码示例。如果您正苦于以下问题:C++ Comm::getNumberOfProcessors方法的具体用法?C++ Comm::getNumberOfProcessors怎么用?C++ Comm::getNumberOfProcessors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Comm
的用法示例。
在下文中一共展示了Comm::getNumberOfProcessors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char **argv)
{
CGMTimers *timers = new CGMTimers ();
Comm *comm = Comm::getComm (&argc, &argv, timers);
int tag = 0;
int p = comm->getNumberOfProcessors ();
//printf("Number of processors %d\n",p);
int id = comm->getMyId ();
//printf("ID%d\n",id);
int sendTo = (id + 1) % p;
int receiveFrom = (id - 1 + p) % p;
int actualSource = -1;
vector<int> values;
if (argc > 1)
{
char *size=strtok(argv[1],",");
while (size!=NULL)
{
values.push_back(atoi(size));
size=strtok(NULL,",");
}
}
else
{
printf("Falt argumento com os tamanhos das matrices: ex. 1,3,4,5,6\n");
}
// printf("size %d\n",values.size());
// int bloco=(values.size()-1)/p;
//printf("Bloco %d\n",bloco);
SimpleCommObject<int> sample(0);
int matrix_size=values.size()-1;
int **total_matrix=new int*[matrix_size];
for (int i=0;i<matrix_size;i++)
total_matrix[i]=new int[matrix_size];
for (int row=0;row<matrix_size;row++)
for (int col=0;col<matrix_size;col++)
{
if (row==col)
total_matrix[row][row]=0;
else
total_matrix[row][col]=-1;
}
int *blocos=new int[p];
int q=(values.size()-1)/p;
if (q<1) q=1;
int r=(values.size()-1)%p;
if (r<1) r=0;
for (int i=0;i<p;i++)
{
if (i<r)
blocos[i]=q+1;
else
blocos[i]=q;
}
//printf("ID: %d Bloco: %d\n",id,blocos[id]);
int bloco_offset=0;
for (int i=0;i<id;i++)
bloco_offset+=blocos[i];
//int row_start=blocos[id]*id;
int row_start=bloco_offset;
int row_end=row_start+blocos[id]-1;
//printf("ID %d, row_start %d row_end %d\n",id,row_start, row_end);
for (int rodada=0;rodada<=p-id-1;rodada++)
{
//printf("ID %d RODADA %d\n",id,rodada);
//int col_start=blocos[id]*(rodada+id);
int col_start=bloco_offset+(blocos[id]*rodada);
//int col_end=blocos[id]*(rodada+id+1)-1;
int col_end=col_start+blocos[id]-1;
if (col_start>values.size()-2)
break;
// printf("ID %d, col_start %d, col_end %d RODADA: %d\n",id,col_start, col_end,rodada);
CommObjectList data_to_send(&sample);
workOnSubMatrix(&total_matrix, &values, row_start,row_end,col_start,col_end, rodada, blocos[id], id);
//printf("ID: %d SAIU RODADA: %d\n",id,rodada);
int **submatrix=new int*[row_end-row_start+1];
for (int i=0;i<row_end-row_start+1;i++)
submatrix[i]=new int[col_end-col_start+1];
/*if (id==1)
{
for (int row=0;row<matrix_size;row++)
{
for (int col=0;col<matrix_size;col++)
{
printf("R>%d %d,%d=%d ",rodada,row,col,total_matrix[row][col]);
}
printf("\n");
}
}*/
convertMatrixToList(&total_matrix,row_start, col_end, col_start, col_end, &data_to_send,id,rodada);
//printf("ID: %d, COPIOU SUBM RODADA: %d\n",id,rodada);
CommObjectList data_to_receive(&sample);
if (id!=0)
{
//printf("ID: %d IS SENDING RODADA: %d\n",id,rodada);
//.........这里部分代码省略.........