00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <cmtkconfig.h>
00034
00035 #ifdef CMTK_BUILD_MPI
00036
00037 #include <Base/cmtkUniformVolume.h>
00038
00039 #include <IO/cmtkMPI.h>
00040
00041 #include <mpi.h>
00042
00043 namespace cmtk
00044 {
00045
00048 namespace mpi
00049 {
00050
00051 template<>
00052 void
00053 Broadcast
00054 ( MPI::Intracomm& comm, UniformVolume::SmartPtr& inOutPtr, const int root )
00055 {
00056 const size_t msgBufferHdrSize =
00057 3 * sizeof(int) +
00058 6 * sizeof(int) +
00059 3 * sizeof( Types::Coordinate ) +
00060 3 * sizeof( Types::Coordinate ) +
00061 sizeof( ScalarDataType );
00062
00063 char msgBufferHdr[ msgBufferHdrSize ];
00064
00065 if ( comm.Get_rank() == root )
00066 {
00067
00068 int position = 0;
00069 MPI::CHAR.Pack( inOutPtr->GetDims().begin(), 3 * sizeof( inOutPtr->GetDims()[0] ), msgBufferHdr, msgBufferHdrSize, position, comm );
00070
00071 const cmtk::DataGrid::RegionType& cropRegion = inOutPtr->CropRegion();
00072
00073 const int cropFrom[3] = { cropRegion.From()[0], cropRegion.From()[1], cropRegion.From()[2] };
00074 const int cropTo[3] = { cropRegion.To()[0], cropRegion.To()[1], cropRegion.To()[2] };
00075 MPI::CHAR.Pack( cropFrom, sizeof( cropFrom ), msgBufferHdr, msgBufferHdrSize, position, comm );
00076 MPI::CHAR.Pack( cropTo, sizeof( cropTo ), msgBufferHdr, msgBufferHdrSize, position, comm );
00077
00078 MPI::CHAR.Pack( inOutPtr->Size.begin(), 3 * sizeof( inOutPtr->Size[0] ), msgBufferHdr, msgBufferHdrSize, position, comm );
00079
00080 MPI::CHAR.Pack( inOutPtr->m_Offset.begin(), 3 * sizeof( inOutPtr->m_Offset[0] ), msgBufferHdr, msgBufferHdrSize, position, comm );
00081
00082 ScalarDataType dataType = TYPE_NONE;
00083 const TypedArray* inData = inOutPtr->GetData();
00084 if ( inData )
00085 {
00086 dataType = inData->GetType();
00087 }
00088 MPI::CHAR.Pack( &dataType, sizeof( dataType ), msgBufferHdr, msgBufferHdrSize, position, comm );
00089 }
00090
00091 comm.Bcast( msgBufferHdr, msgBufferHdrSize, MPI::CHAR, root );
00092
00093 if ( comm.Get_rank() != root )
00094 {
00095
00096 int dims[3];
00097 int cropRegionFrom[3];
00098 int cropRegionTo[3];
00099 Types::Coordinate size[3];
00100 Types::Coordinate offset[3];
00101 ScalarDataType dataType;
00102
00103 int position = 0;
00104 MPI::CHAR.Unpack( msgBufferHdr, msgBufferHdrSize, dims, sizeof( dims ), position, comm );
00105 MPI::CHAR.Unpack( msgBufferHdr, msgBufferHdrSize, cropRegionFrom, sizeof( cropRegionFrom ), position, comm );
00106 MPI::CHAR.Unpack( msgBufferHdr, msgBufferHdrSize, cropRegionTo, sizeof( cropRegionTo ), position, comm );
00107 MPI::CHAR.Unpack( msgBufferHdr, msgBufferHdrSize, size, sizeof( size ), position, comm );
00108 MPI::CHAR.Unpack( msgBufferHdr, msgBufferHdrSize, offset, sizeof( offset ), position, comm );
00109 MPI::CHAR.Unpack( msgBufferHdr, msgBufferHdrSize, &dataType, sizeof( dataType ), position, comm );
00110
00111 inOutPtr = UniformVolume::SmartPtr( new UniformVolume( UniformVolume::IndexType( dims ), UniformVolume::CoordinateVectorType( size ) ) );
00112 inOutPtr->SetOffset( FixedVector<3,Types::Coordinate>( offset ) );
00113 inOutPtr->CropRegion() = cmtk::DataGrid::RegionType( cmtk::DataGrid::IndexType( cropRegionFrom ), cmtk::DataGrid::IndexType( cropRegionTo ) );
00114 inOutPtr->CreateDataArray( dataType );
00115 }
00116
00117 comm.Bcast( inOutPtr->GetData()->GetDataPtr(), inOutPtr->GetData()->GetDataSizeBytes(), MPI::CHAR, root );
00118 }
00119
00120 template void Broadcast<UniformVolume>( ::MPI::Intracomm&, SmartPointer<UniformVolume>&, const int );
00121
00122 }
00123
00125
00126 }
00127
00128
00129 #endif // #ifdef CMTK_BUILD_MPI