Ignore:
Timestamp:
07/12/11 17:47:39 (14 years ago)
Author:
Eric.Larour
Message:

Implemented Mat Array for qmu.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/io/Disk/IoModelFetchData.cpp

    r8926 r8936  
    215215        *pinteger=integer;
    216216
     217}
     218/*}}}*/
     219/*FUNCTION IoModelFetchData(double*** pmatrices,int** pmdims,int** pndims, int* pM,FILE* model_handle,int data_enum){{{1*/
     220void  IoModelFetchData(double*** pmatrices,int** pmdims,int** pndims, int* pnumrecords,FILE* model_handle,int data_enum){
     221
     222        int i;
     223
     224        extern int my_rank;
     225        extern int num_procs;
     226
     227        /*output: */
     228        double** matrices=NULL;
     229        int*     mdims=NULL;
     230        int*     ndims=NULL;
     231        int      numrecords=0;
     232
     233        /*intermediary: */
     234        int M,N;
     235        double* matrix=NULL;
     236       
     237        FILE* fid=NULL;
     238       
     239        /*Set file pointer to beginning of the data: */
     240        fid=SetFilePointerToData(model_handle,data_enum);
     241       
     242        /*Now fetch: */
     243        if(my_rank==0){ 
     244                if(fread(&numrecords,sizeof(int),1,fid)!=1) _error_("could not read number of records in matrix array ");
     245        }
     246        MPI_Bcast(&numrecords,1,MPI_INT,0,MPI_COMM_WORLD);
     247
     248        if(numrecords){
     249
     250                /*Allocate matrices :*/
     251                matrices=(double**)xmalloc(numrecords*sizeof(double*));
     252                mdims=(int*)xmalloc(numrecords*sizeof(int));
     253                ndims=(int*)xmalloc(numrecords*sizeof(int));
     254
     255                for(i=0;i<numrecords;i++){
     256                        matrices[i]=NULL;
     257                        mdims[i]=NULL;
     258                        ndims[i]=NULL;
     259                }
     260
     261                /*Loop through records and fetch matrix: */
     262                for(i=0;i<numrecords;i++){
     263
     264                        if(my_rank==0){ 
     265                                if(fread(&M,sizeof(int),1,fid)!=1) _error_("%s%i%s","could not read number of rows in ",i,"th matrix of matrix array");
     266                        }
     267                        MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD);
     268
     269                        if(my_rank==0){ 
     270                                if(fread(&N,sizeof(int),1,fid)!=1) _error_("%s%i%s","could not read number of columns in ",i,"th matrix of matrix array");
     271                        }
     272                        MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD);
     273
     274                        /*Now allocate matrix: */
     275                        if(M*N){
     276                                matrix=(double*)xmalloc(M*N*sizeof(double));
     277
     278                                /*Read matrix on node 0, then broadcast: */
     279                                if(my_rank==0){ 
     280                                        if(fread(matrix,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix ");
     281                                }
     282
     283                                MPI_Bcast(matrix,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD);
     284                        }
     285
     286                        /*Assign: */
     287                        matrices[i]=matrix;
     288                        mdims[i]=M;
     289                        ndims[i]=N;
     290                }
     291        }
     292
     293        /*Assign output pointers: */
     294        *pmatrices=matrices;
     295        *pmdims=mdims;
     296        *pndims=ndims;
     297        *pnumrecords=numrecords;
    217298}
    218299/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.