Changeset 11239


Ignore:
Timestamp:
01/27/12 08:41:40 (13 years ago)
Author:
Mathieu Morlighem
Message:

Find the first cpu that has at least one element to output results instead of cpu 0, which might be empty

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/Container/Elements.cpp

    r11237 r11239  
    180180        int    numberofvertices,numberofelements;
    181181        int    numberofresults,vectorsize;
     182        int    rank;
     183        int    minrank;
    182184
    183185        /*Recover parameters: */
     
    190192                /*No patch here, we prepare vectors*/
    191193
     194                /*Get rank of first cpu that has results*/
     195                if(this->Size()) rank=my_rank;
     196                else rank=num_procs;
     197                MPI_Allreduce (&rank,&minrank,1,MPI_INT,MPI_MIN,MPI_COMM_WORLD);
     198
    192199                /*see what the first element of this partition has in stock (this is common to all partitions)*/
    193                 if(my_rank==0){
    194                         if(this->Size()==0) _error_("Cannot write results because first partition has no element. Maybe too many cpus were requested");
     200                if(my_rank==minrank){
     201                        if(this->Size()==0) _error_("Cannot write results because there is no element??");
    195202                        Element* element=(Element*)this->GetObjectByOffset(0);
    196203                        element->ListResultsInfo(&resultsenums,&resultssizes,&resultstimes,&resultssteps,&numberofresults);
    197204                }
    198                 MPI_Bcast(&numberofresults,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
     205                MPI_Bcast(&numberofresults,1,MPI_DOUBLE,minrank,MPI_COMM_WORLD);
     206
    199207                /*Get out if there is no results. Otherwise broadcast info*/
    200208                if(!numberofresults) return;
    201                 if(my_rank!=0){
     209                if(my_rank!=minrank){
    202210                        resultsenums=(int*)xmalloc(numberofresults*sizeof(int));
    203211                        resultssizes=(int*)xmalloc(numberofresults*sizeof(int));
     
    205213                        resultssteps=(int*)xmalloc(numberofresults*sizeof(int));
    206214                }
    207                 MPI_Bcast(resultsenums,numberofresults,MPI_INT,0,MPI_COMM_WORLD);
    208                 MPI_Bcast(resultssizes,numberofresults,MPI_INT,0,MPI_COMM_WORLD);
    209                 MPI_Bcast(resultstimes,numberofresults,MPI_DOUBLE,0,MPI_COMM_WORLD);
    210                 MPI_Bcast(resultssteps,numberofresults,MPI_INT,0,MPI_COMM_WORLD);
     215                MPI_Bcast(resultsenums,numberofresults,MPI_INT,minrank,MPI_COMM_WORLD);
     216                MPI_Bcast(resultssizes,numberofresults,MPI_INT,minrank,MPI_COMM_WORLD);
     217                MPI_Bcast(resultstimes,numberofresults,MPI_DOUBLE,minrank,MPI_COMM_WORLD);
     218                MPI_Bcast(resultssteps,numberofresults,MPI_INT,minrank,MPI_COMM_WORLD);
    211219
    212220                /*Loop over all results and get nodal vector*/
Note: See TracChangeset for help on using the changeset viewer.