File: XdmfDsm.cxx

package info (click to toggle)
vtk6 6.1.0+dfsg2-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 165,164 kB
  • ctags: 226,428
  • sloc: cpp: 1,354,490; ansic: 730,748; python: 227,134; tcl: 48,285; xml: 8,290; yacc: 4,832; java: 3,827; perl: 3,108; lex: 1,809; sh: 1,437; asm: 471; makefile: 229
file content (262 lines) | stat: -rw-r--r-- 9,081 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*******************************************************************/
/*                               XDMF                              */
/*                   eXtensible Data Model and Format              */
/*                                                                 */
/*  Id : Id  */
/*  Date : $Date$ */
/*  Version : $Revision$ */
/*                                                                 */
/*  Author:                                                        */
/*     Jerry A. Clarke                                             */
/*     clarke@arl.army.mil                                         */
/*     US Army Research Laboratory                                 */
/*     Aberdeen Proving Ground, MD                                 */
/*                                                                 */
/*     Copyright @ 2007 US Army Research Laboratory                */
/*     All Rights Reserved                                         */
/*     See Copyright.txt or http://www.arl.hpc.mil/ice for details */
/*                                                                 */
/*     This software is distributed WITHOUT ANY WARRANTY; without  */
/*     even the implied warranty of MERCHANTABILITY or FITNESS     */
/*     FOR A PARTICULAR PURPOSE.  See the above copyright notice   */
/*     for more information.                                       */
/*                                                                 */
/*******************************************************************/
#include "XdmfDsm.h"
#include "XdmfDsmComm.h"
#include "XdmfDsmMsg.h"
#include "XdmfArray.h"

// Align
typedef struct {
    XdmfInt64   Opcode;
    XdmfInt64   Source;
    XdmfInt64   Target;
    XdmfInt64   Address;
    XdmfInt64   Length;
    XdmfInt64   Parameters[10];
} XdmfDsmCommand;

XdmfDsm::XdmfDsm() {
    this->DsmType = XDMF_DSM_TYPE_UNIFORM;
    this->Storage = new XdmfArray;
    this->StorageIsMine = 1;
    this->Locks = 0;
    // For Alignment
    this->Storage->SetNumberType(XDMF_INT64_TYPE);
    this->SetLength(XDMF_DSM_DEFAULT_LENGTH);
    this->DataPointer = (XdmfByte *)this->Storage->GetDataPointer();
    this->StartAddress = 0;
    this->EndAddress = this->StartAddress + this->Length - 1;
    this->Comm = 0;
    this->StartServerId = this->EndServerId = -1;
    this->Msg = new XdmfDsmMsg;
}

XdmfDsm::~XdmfDsm() {
    if(this->Storage && this->StorageIsMine) delete this->Storage;
    if(this->Msg) delete this->Msg;
}

XdmfInt32
XdmfDsm::Copy(XdmfDsm *Source){
    this->DsmType = Source->DsmType;
    if (this->Storage) delete this->Storage;
    this->Storage = Source->GetStorage();
    this->StorageIsMine = 0;
    this->DataPointer = (XdmfByte *)this->Storage->GetDataPointer();
    // For Alignment
    this->Length = Source->Length;
    this->StartAddress = Source->StartAddress;
    this->EndAddress = Source->EndAddress;
    this->Comm = Source->Comm;
    this->StartServerId = Source->StartServerId;
    this->EndServerId = Source->EndServerId;
    this->Locks = Source->Locks;
    // Always make a new Message so there is no contention
    if (this->Msg) delete this->Msg;
    this->Msg = new XdmfDsmMsg;
    return(XDMF_SUCCESS);
}

XdmfInt32
XdmfDsm::SetStorage(XdmfArray *aStorage){
    if(this->Storage && this->StorageIsMine) delete this->Storage;
    this->Storage = aStorage;
    this->DataPointer = (XdmfByte *)this->Storage->GetDataPointer();
    return(XDMF_SUCCESS);
}

XdmfInt32
XdmfDsm::ConfigureUniform(XdmfDsmComm *aComm, XdmfInt64 aLength, XdmfInt32 StartId, XdmfInt32 EndId){
    if(StartId < 0) StartId = 0;
    if(EndId < 0) EndId = aComm->GetTotalSize() - 1;
    this->SetDsmType(XDMF_DSM_TYPE_UNIFORM_RANGE);
    if((StartId == 0) && (EndId == aComm->GetTotalSize() - 1)){
        this->SetDsmType(XDMF_DSM_TYPE_UNIFORM);
    }
    this->SetStartServerId(StartId);
    this->SetEndServerId(EndId);
    this->SetComm(aComm);
    if((aComm->GetId() >= StartId) && (aComm->GetId() <= EndId)){
        this->SetLength(aLength);
        this->StartAddress = (aComm->GetId() - StartId) * aLength;
        this->EndAddress = this->StartAddress + aLength - 1;
    }else{
        this->Length = aLength;
    }
    this->Msg->Source = this->Comm->GetId();
    this->TotalLength = aLength * (EndId - StartId + 1);
    return(XDMF_SUCCESS);
}

XdmfInt32
XdmfDsm::GetAddressRangeForId(XdmfInt32 Id, XdmfInt64 *Start, XdmfInt64 *End){
    switch(this->DsmType) {
        case XDMF_DSM_TYPE_UNIFORM :
        case XDMF_DSM_TYPE_UNIFORM_RANGE :
            // All Servers have same length
            *Start = (Id - this->StartServerId) * this->Length;
            *End = *Start + Length - 1;
            break;
        default :
            // Not Implemented
            XdmfErrorMessage("DsmType " << this->DsmType << " not yet implemented");
            return(XDMF_FAIL);
            break;
    }
    return(XDMF_SUCCESS);
}

XdmfInt32
XdmfDsm::AddressToId(XdmfInt64 Address){
    XdmfInt32   ServerId = XDMF_FAIL;

    switch(this->DsmType) {
        case XDMF_DSM_TYPE_UNIFORM :
        case XDMF_DSM_TYPE_UNIFORM_RANGE :
            // All Servers have same length
            ServerId = this->StartServerId + (Address / this->Length);
            if(ServerId > this->EndServerId ){
                XdmfErrorMessage("ServerId " << ServerId << " for Address " << Address << " is larger than EndServerId " << this->EndServerId);
            }
            break;
        default :
            // Not Implemented
            XdmfErrorMessage("DsmType " << this->DsmType << " not yet implemented");
            break;
    }
    return(ServerId);
}

XdmfInt32
XdmfDsm::SendDone(){
    XdmfInt32   who, status = XDMF_SUCCESS;

    switch(this->DsmType) {
        case XDMF_DSM_TYPE_UNIFORM :
        case XDMF_DSM_TYPE_UNIFORM_RANGE :
            for(who = this->StartServerId ; who <= this->EndServerId ; who++){
                status = this->SendCommandHeader(XDMF_DSM_OPCODE_DONE, who, 0, 0);
            }
            break;
        default :
            // Not Implemented
            XdmfErrorMessage("DsmType " << this->DsmType << " not yet implemented");
            break;
    }
    return(status);
}

XdmfInt32
XdmfDsm::SetLength(XdmfInt64 aLength){
    // Make it longer than actually needed for round off.
    if(this->Storage->SetNumberOfElements((aLength / sizeof(XdmfInt64)) + 1) != XDMF_SUCCESS){
        XdmfErrorMessage("Cannot set Dsm Length to " << Length);
        return(XDMF_FAIL);
    }
    this->Length = aLength;
    this->DataPointer = (XdmfByte *)this->Storage->GetDataPointer();
    return(XDMF_SUCCESS);
}

XdmfInt32
XdmfDsm::SendCommandHeader(XdmfInt32 Opcode, XdmfInt32 Dest, XdmfInt64 Address, XdmfInt64 aLength){
    XdmfDsmCommand  Cmd;
    XdmfInt32 Status;

    Cmd.Opcode = Opcode;
    Cmd.Source = this->Comm->GetId();
    Cmd.Target = Dest;
    Cmd.Address = Address;
    Cmd.Length = aLength;

    this->Msg->SetSource(this->Comm->GetId());
    this->Msg->SetDest(Dest);
    this->Msg->SetTag(XDMF_DSM_COMMAND_TAG);
    this->Msg->SetLength(sizeof(Cmd));
    this->Msg->SetData(&Cmd);

    Status = this->Comm->Send(this->Msg);
    XdmfDebug("(" << this->Comm->GetId() << ") sent opcode " << Cmd.Opcode);
    return(Status);
}

XdmfInt32
XdmfDsm::ReceiveCommandHeader(XdmfInt32 *Opcode, XdmfInt32 *Source, XdmfInt64 *Address, XdmfInt64 *aLength, XdmfInt32 Block){
    XdmfDsmCommand  Cmd;
    XdmfInt32       status = XDMF_FAIL;

    this->Msg->Source = XDMF_DSM_ANY_SOURCE;
    this->Msg->SetLength(sizeof(Cmd));
    this->Msg->SetTag(XDMF_DSM_COMMAND_TAG);
    this->Msg->SetData(&Cmd);

    memset(&Cmd, 0, sizeof(XdmfDsmCommand));
    status = this->Comm->Check(this->Msg);
    if((status != XDMF_FAIL) || Block){
        status  = this->Comm->Receive(this->Msg);
        if(status == XDMF_FAIL){
            XdmfErrorMessage("Communicator Receive Failed");
            return(XDMF_FAIL);
        }else{
            *Opcode = Cmd.Opcode;
            *Source = Cmd.Source;
            *Address = Cmd.Address;
            *aLength = Cmd.Length;
            status = XDMF_SUCCESS;
            XdmfDebug("(Server " << this->Comm->GetId() << ") got opcode " << Cmd.Opcode);
        }
    }
    return(status);
}

XdmfInt32
XdmfDsm::SendData(XdmfInt32 Dest, void *Data, XdmfInt64 aLength){

    this->Msg->SetSource(this->Comm->GetId());
    this->Msg->SetDest(Dest);
    this->Msg->SetLength(aLength);
    // this->Msg->SetTag(XDMF_DSM_RESPONSE_TAG);
    this->Msg->SetData(Data);
    return(this->Comm->Send(this->Msg));
}

XdmfInt32
XdmfDsm::ReceiveData(XdmfInt32 Source, void *Data, XdmfInt64 aLength, XdmfInt32 Block){
    XdmfInt32   Status = XDMF_FAIL;

    this->Msg->SetSource(Source);
    this->Msg->SetLength(aLength);
    // this->Msg->SetTag(XDMF_DSM_RESPONSE_TAG);
    this->Msg->SetData(Data);
    if(Block){
        Status = this->Comm->Receive(this->Msg);
    }else{
        Status = this->Comm->Check(this->Msg);
        if(Status == XDMF_SUCCESS){
            Status = this->Comm->Receive(this->Msg);
        }
    }
    return(Status);
}