Changeset 17627
- Timestamp:
- 04/02/14 15:36:30 (11 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/IoModel.cpp
r17225 r17627 445 445 /*Ok, we have reached the end of the file. break: */ 446 446 record_code=0; //0 means bailout 447 ISSM_MPI_Bcast (&record_code,1,ISSM_MPI_INT,0,IssmComm::GetComm()); /*tell others cpus we are bailing: */447 ISSM_MPI_Bcast<int>(&record_code,1,0,IssmComm::GetComm()); /*tell others cpus we are bailing: */ 448 448 break; 449 449 } … … 653 653 if(fread(&booleanint,sizeof(int),1,fid)!=1) _error_("could not read boolean "); 654 654 } 655 ISSM_MPI_Bcast (&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());655 ISSM_MPI_Bcast<int>(&booleanint,1,0,IssmComm::GetComm()); 656 656 657 657 /*cast to bool: */ … … 683 683 } 684 684 685 ISSM_MPI_Bcast (&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());685 ISSM_MPI_Bcast<int>(&integer,1,0,IssmComm::GetComm()); 686 686 687 687 /*Assign output pointers: */ … … 710 710 if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar "); 711 711 } 712 ISSM_MPI_Bcast (&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());712 ISSM_MPI_Bcast<IssmPDouble>(&scalar,1,0,IssmComm::GetComm()); 713 713 714 714 /*Assign output pointers: */ … … 742 742 } 743 743 744 ISSM_MPI_Bcast (&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());744 ISSM_MPI_Bcast<int>(&string_size,1,0,IssmComm::GetComm()); 745 745 746 746 /*Now allocate string: */ … … 753 753 if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string "); 754 754 } 755 ISSM_MPI_Bcast (string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());755 ISSM_MPI_Bcast<char>(string,string_size,0,IssmComm::GetComm()); 756 756 } 757 757 else{ … … 792 792 } 793 793 794 ISSM_MPI_Bcast (&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());794 ISSM_MPI_Bcast<int>(&M,1,0,IssmComm::GetComm()); 795 795 796 796 if(my_rank==0){ 797 797 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 798 798 } 799 ISSM_MPI_Bcast (&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());799 ISSM_MPI_Bcast<int>(&N,1,0,IssmComm::GetComm()); 800 800 801 801 /*Now allocate matrix: */ … … 808 808 } 809 809 810 ISSM_MPI_Bcast (matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());810 ISSM_MPI_Bcast<IssmPDouble>(matrix,M*N,0,IssmComm::GetComm()); 811 811 } 812 812 … … 857 857 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 858 858 } 859 ISSM_MPI_Bcast (&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());859 ISSM_MPI_Bcast<int>(&M,1,0,IssmComm::GetComm()); 860 860 861 861 if(my_rank==0){ 862 862 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 863 863 } 864 ISSM_MPI_Bcast (&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());864 ISSM_MPI_Bcast<int>(&N,1,0,IssmComm::GetComm()); 865 865 866 866 /*Now allocate matrix: */ … … 872 872 if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 873 873 } 874 ISSM_MPI_Bcast (matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());874 ISSM_MPI_Bcast<IssmPDouble>(matrix,M*N,0,IssmComm::GetComm()); 875 875 876 876 _assert_(this->independents); … … 921 921 if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_("could not read length of string array"); 922 922 } 923 ISSM_MPI_Bcast (&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());923 ISSM_MPI_Bcast<int>(&numstrings,1,0,IssmComm::GetComm()); 924 924 925 925 /*Now allocate string array: */ … … 934 934 if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string "); 935 935 } 936 ISSM_MPI_Bcast (&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());936 ISSM_MPI_Bcast<int>(&string_size,1,0,IssmComm::GetComm()); 937 937 if(string_size){ 938 938 string=xNew<char>((string_size+1)); … … 943 943 if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string "); 944 944 } 945 ISSM_MPI_Bcast (string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());945 ISSM_MPI_Bcast<char>(string,string_size,0,IssmComm::GetComm()); 946 946 } 947 947 else{ … … 988 988 if(fread(&numrecords,sizeof(int),1,fid)!=1) _error_("could not read number of records in matrix array "); 989 989 } 990 ISSM_MPI_Bcast (&numrecords,1,ISSM_MPI_INT,0,IssmComm::GetComm());990 ISSM_MPI_Bcast<int>(&numrecords,1,0,IssmComm::GetComm()); 991 991 992 992 if(numrecords){ … … 1009 1009 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows in " << i << "th matrix of matrix array"); 1010 1010 } 1011 ISSM_MPI_Bcast (&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());1011 ISSM_MPI_Bcast<int>(&M,1,0,IssmComm::GetComm()); 1012 1012 1013 1013 if(my_rank==0){ 1014 1014 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns in " << i << "th matrix of matrix array"); 1015 1015 } 1016 ISSM_MPI_Bcast (&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());1016 ISSM_MPI_Bcast<int>(&N,1,0,IssmComm::GetComm()); 1017 1017 1018 1018 /*Now allocate matrix: */ … … 1025 1025 } 1026 1026 1027 ISSM_MPI_Bcast (matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());1027 ISSM_MPI_Bcast<IssmPDouble>(matrix,M*N,0,IssmComm::GetComm()); 1028 1028 matrices[i]=xNew<IssmDouble>(M*N); 1029 1029 for (int j=0;j<M*N;++j) {matrices[i][j]=matrix[j];} … … 1169 1169 } 1170 1170 1171 ISSM_MPI_Bcast (&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());1171 ISSM_MPI_Bcast<int>(&string_size,1,0,IssmComm::GetComm()); 1172 1172 1173 1173 /*Now allocate string: */ … … 1180 1180 if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string "); 1181 1181 } 1182 ISSM_MPI_Bcast (string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());1182 ISSM_MPI_Bcast<char>(string,string_size,0,IssmComm::GetComm()); 1183 1183 } 1184 1184 else{ … … 1236 1236 } 1237 1237 } 1238 ISSM_MPI_Bcast (&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());1238 ISSM_MPI_Bcast<int>(&integer,1,0,IssmComm::GetComm()); 1239 1239 1240 1240 /*Assign: */ … … 1295 1295 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 1296 1296 } 1297 ISSM_MPI_Bcast (&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());1297 ISSM_MPI_Bcast<int>(&M,1,0,IssmComm::GetComm()); 1298 1298 1299 1299 if(my_rank==0){ 1300 1300 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 1301 1301 } 1302 ISSM_MPI_Bcast (&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());1302 ISSM_MPI_Bcast<int>(&N,1,0,IssmComm::GetComm()); 1303 1303 1304 1304 … … 1311 1311 if(fread(pmatrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 1312 1312 } 1313 ISSM_MPI_Bcast (pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());1313 ISSM_MPI_Bcast<IssmPDouble>(pmatrix,M*N,0,IssmComm::GetComm()); 1314 1314 1315 1315 _assert_(this->independents); … … 1401 1401 if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix "); 1402 1402 } 1403 ISSM_MPI_Bcast (&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());1403 ISSM_MPI_Bcast<int>(&M,1,0,IssmComm::GetComm()); 1404 1404 1405 1405 if(my_rank==0){ 1406 1406 if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix "); 1407 1407 } 1408 ISSM_MPI_Bcast (&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());1408 ISSM_MPI_Bcast<int>(&N,1,0,IssmComm::GetComm()); 1409 1409 1410 1410 … … 1418 1418 if(fread(pmatrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix "); 1419 1419 } 1420 ISSM_MPI_Bcast (pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());1420 ISSM_MPI_Bcast<IssmPDouble>(pmatrix,M*N,0,IssmComm::GetComm()); 1421 1421 1422 1422 _assert_(this->independents); … … 1594 1594 } 1595 1595 /*Broadcast code and vector type: */ 1596 ISSM_MPI_Bcast (&lastindex,1,ISSM_MPI_INT,0,IssmComm::GetComm());1596 ISSM_MPI_Bcast<int>(&lastindex,1,0,IssmComm::GetComm()); 1597 1597 1598 1598 /*Assign output pointers:*/ … … 1650 1650 } 1651 1651 } 1652 ISSM_MPI_Bcast (&found,1,ISSM_MPI_INT,0,IssmComm::GetComm());1652 ISSM_MPI_Bcast<int>(&found,1,0,IssmComm::GetComm()); 1653 1653 if(!found)_error_("could not find data with name " << EnumToStringx(data_enum) << " in binary file"); 1654 1654 1655 1655 /*Broadcast code and vector type: */ 1656 ISSM_MPI_Bcast (&record_code,1,ISSM_MPI_INT,0,IssmComm::GetComm());1657 ISSM_MPI_Bcast (&vector_type,1,ISSM_MPI_INT,0,IssmComm::GetComm());1656 ISSM_MPI_Bcast<int>(&record_code,1,0,IssmComm::GetComm()); 1657 ISSM_MPI_Bcast<int>(&vector_type,1,0,IssmComm::GetComm()); 1658 1658 1659 1659 /*Assign output pointers:*/ … … 1754 1754 1755 1755 /*Broadcast data: */ 1756 ISSM_MPI_Bcast (&num_instances,1,ISSM_MPI_INT,0,IssmComm::GetComm());1756 ISSM_MPI_Bcast<int>(&num_instances,1,0,IssmComm::GetComm()); 1757 1757 1758 1758 /*Assign output pointers:*/ -
issm/trunk-jpl/src/c/toolkits/mpi/issmmpi.h
r16144 r17627 12 12 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 13 13 #endif 14 15 14 #include <cstddef> 15 #include <cassert> 16 #include "../../shared/Numerics/types.h" 16 17 17 18 #ifdef _HAVE_MPI_ … … 83 84 /*}}}*/ 84 85 # endif 86 87 template <class T> ISSM_MPI_Datatype TypeToMPIType(){assert(false);}; 88 template <> inline ISSM_MPI_Datatype TypeToMPIType<IssmDouble>(){return ISSM_MPI_DOUBLE;}; 89 #if _HAVE_ADOLC_ 90 template <> inline ISSM_MPI_Datatype TypeToMPIType<IssmPDouble>(){return ISSM_MPI_PDOUBLE;}; 91 #endif 92 template <> inline ISSM_MPI_Datatype TypeToMPIType<int>(){return ISSM_MPI_INT;}; 93 template <> inline ISSM_MPI_Datatype TypeToMPIType<char>(){return ISSM_MPI_CHAR;}; 94 template <class T> ISSM_MPI_Datatype ISSM_MPI_Reduce(T *sendbuf,T *recvbuf,int count,ISSM_MPI_Op op, int root, ISSM_MPI_Comm comm){ /*{{{*/ 95 96 /*Get MPI type*/ 97 ISSM_MPI_Datatype datatype = TypeToMPIType<T>(); 98 99 int rc=0; 100 #ifdef _HAVE_MPI_ 101 # ifdef _HAVE_AMPI_ 102 rc=AMPI_Reduce(sendbuf, 103 recvbuf, 104 count, 105 datatype, 106 op, 107 root, 108 comm); 109 # else 110 rc=MPI_Reduce(sendbuf, 111 recvbuf, 112 count, 113 datatype, 114 op, 115 root, 116 comm); 117 # endif 118 #else 119 # ifdef _HAVE_ADOLC_ 120 if (datatype==ISSM_MPI_DOUBLE) { 121 IssmDouble* activeSendBuf=(IssmDouble*)sendbuf; 122 IssmDouble* activeRecvBuf=(IssmDouble*)recvbuf; 123 for(int i=0;i<count;++i) activeRecvBuf[i]=activeSendBuf[i]; 124 } 125 else 126 # endif 127 memcpy(recvbuf,sendbuf,sizeHelper(datatype)*count); 128 #endif 129 return rc; 130 }/*}}}*/ 131 template <class T> int ISSM_MPI_Bcast(T *buffer, int count,int root, ISSM_MPI_Comm comm){ /*{{{*/ 132 133 int rc=0; 134 135 /*Get MPI type*/ 136 ISSM_MPI_Datatype datatype = TypeToMPIType<T>(); 137 138 #ifdef _HAVE_MPI_ 139 # ifdef _HAVE_AMPI_ 140 rc=AMPI_Bcast(buffer, 141 count, 142 datatype, 143 root, 144 comm); 145 # else 146 rc=MPI_Bcast(buffer, 147 count, 148 datatype, 149 root, 150 comm); 151 # endif 152 #else 153 // nothing to be done here 154 #endif 155 return rc; 156 }/*}}}*/ 157 85 158 /* interfaces {{{*/ 86 159 int ISSM_MPI_Allgather(void *sendbuf, int sendcount, ISSM_MPI_Datatype sendtype, void *recvbuf, int recvcount, ISSM_MPI_Datatype recvtype, ISSM_MPI_Comm comm);
Note:
See TracChangeset
for help on using the changeset viewer.