I am having a relatively a problem,I have defined struct and I want the array of structure has this information (processor name and the computation time for the processor) this is part of my code :
struct stru
{
double arr_time[50];
char pname[50];
};
int main (int argc, char *argv[])
{
struct stru all_info[50];
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&process_id);
MPI_Comm_size(MPI_COMM_WORLD,&num_of_processes);
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
if (process_id == 0)
{ //do somthing
}
if (process_id > 0)
{
double start = MPI_Wtime();
for (k=0; k<array_size; k++)
for (i=0; i<rows; i++)
{
c[i][k]=0.0;
for (j=0; j<array_size; j++)
c[i][k] = c[i][k] + a[i][j] * b[j][k];
}
end_time = MPI_Wtime() - start;
all_info[i].arr_time[i] = end_time;
for (int i=1 ;i <= numworkers ;i++)
strcpy( all_info[i].pname, processor_name);
printf(" time = %f for processor %s
\n",all_info[i].arr_time, all_info[i].pname);
}
MPI_Gather( &end_time, 1, MPI_DOUBLE, &all_info[i].arr_time, 1,
MPI_DOUBLE, 0, MPI_COMM_WORLD);
if (process_id == 0){
for(i = 1; i <= numworkers; i++ )
{
printf(" time %f for processor %s
\n",all_info[i].arr_time , all_info[i].pname);
} }
I have no result if I print it in if (process_id == 0) !!!
the out put is
time 0.000000 for processor
time 0.000000 for processor
time 0.000000 for processor
and just the time printed if I printting in if (process_id > 0)
In fact I don't know how can I use Structure with MPI can anyone give me advice how can I generate array of structure that has processor name and his time?
Thank you in advance for your time.