Changeset 1786 for palm/trunk/SOURCE/pmc_server.f90
- Timestamp:
- Mar 8, 2016 5:49:27 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/SOURCE/pmc_server.f90
r1780 r1786 20 20 ! Current revisions: 21 21 ! ------------------ 22 ! 22 ! change in client-server data transfer: server now gets data from client 23 ! instead that client put's it to the server 23 24 ! 24 25 ! Former revisions: … … 336 337 IMPLICIT none 337 338 339 ! 340 !-- Naming convention for appendices: _sc -> server to client transfer 341 !-- _cs -> client to server transfer 342 !-- Send -> Server to client transfer 343 !-- Recv -> client to server transfer 338 344 INTEGER,INTENT(IN) :: ClientId 339 345 … … 347 353 INTEGER,DIMENSION(1024) :: req 348 354 Type(c_ptr) :: base_ptr 349 REAL(kind=wp),DIMENSION(:),POINTER :: base_array 355 REAL(wp),DIMENSION(:),POINTER,SAVE :: base_array_sc !Base array for server to client transfer 356 REAL(wp),DIMENSION(:),POINTER,SAVE :: base_array_cs !Base array for client to server transfer 350 357 INTEGER(KIND=MPI_ADDRESS_KIND) :: WinSize 351 358 359 ! 360 !-- Server to client direction 352 361 myIndex = 1 353 362 rCount = 0 354 363 bufsize = 8 355 364 356 ! First stride, Compute size and set index 357 365 ! 366 !-- First stride: Compute size and set index 358 367 do i=1,Clients(ClientId)%inter_npes 359 368 aPE => Clients(ClientId)%PEs(i) … … 362 371 ar => aPE%array_list(j) 363 372 if(ar%NrDims == 2) then 364 arlen = aPE%NrEle ;! 2D373 arlen = aPE%NrEle ! 2D 365 374 else if(ar%NrDims == 3) then 366 arlen = aPE%NrEle * ar%A_dim(4); ! PALM3D375 arlen = aPE%NrEle * ar%A_dim(4); ! 3D 367 376 else 368 377 arlen = -1 369 378 end if 370 ar% BufIndex = myIndex379 ar%SendIndex = myIndex 371 380 372 381 tag = tag+1 … … 381 390 myIndex = myIndex+arlen 382 391 bufsize = bufsize+arlen 383 ar% BufSize = arlen392 ar%SendSize = arlen 384 393 385 394 end do 386 if(rCount > 0) then 395 if(rCount > 0) then ! Wait for all send completed 387 396 CALL MPI_Waitall (rCount, req, MPI_STATUSES_IGNORE, ierr) 388 397 end if 389 398 end do 390 399 391 ! Create RMA (One Sided Communication) window for data buffer 392 393 CALL PMC_Alloc_mem (base_array, bufsize, base_ptr) 394 Clients(ClientId)%TotalBufferSize = bufsize*wp !Total buffer size in Byte 400 ! 401 !-- Create RMA (One Sided Communication) window for data buffer server to 402 !-- client transfer. 403 !-- The buffer of MPI_Get (counter part of transfer) can be PE-local, i.e. 404 !-- it can but must not be part of the MPI RMA window. 405 !-- Only one RMA window is required to prepare the data 406 !-- for server -> client transfer on the server side and 407 !-- for client -> server transfer on the client side 408 CALL PMC_Alloc_mem (base_array_sc, bufsize) 409 Clients(ClientId)%TotalBufferSize = bufsize*wp !Total buffer size in Byte 395 410 396 411 WinSize = bufsize*wp 397 ! write(9,*) 'PMC_S_SetInd_and_Mem ',m_model_rank,Clients(ClientId)%inter_npes,WinSize,bufsize 398 CALL MPI_Win_create (base_array, WinSize, wp, MPI_INFO_NULL, Clients(ClientId)%intra_comm, Clients(ClientId)%BufWin, ierr); 399 CALL MPI_Win_fence (0, Clients(ClientId)%BufWin, ierr); ! Open Window to set data 400 CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr) 401 402 ! Second stride, Set Buffer pointer 403 412 CALL MPI_Win_create (base_array_sc, WinSize, wp, MPI_INFO_NULL, & 413 Clients(ClientId)%intra_comm, Clients(ClientId)%win_server_client, ierr) 414 CALL MPI_Win_fence (0, Clients(ClientId)%win_server_client, ierr); ! Open Window to set data 415 ! 416 !-- Second stride: Set Buffer pointer 404 417 do i=1,Clients(ClientId)%inter_npes 405 418 aPE => Clients(ClientId)%PEs(i) 406 419 do j=1,aPE%Nr_arrays 407 420 ar => aPE%array_list(j) 408 !-- TO_DO: Adressrechnung ueberlegen? 409 ar%SendBuf = c_loc(base_array(ar%BufIndex)) !kk Adressrechnung ueberlegen 410 if(ar%BufIndex+ar%BufSize > bufsize) then 411 !-- TO_DO: can this error really happen, and what can be the reason? 412 write(0,'(a,i4,4i7,1x,a)') 'Buffer too small ',i,ar%BufIndex,ar%BufSize,ar%BufIndex+ar%BufSize,bufsize,trim(ar%name) 421 ar%SendBuf = c_loc(base_array_sc(ar%SendIndex)) 422 if(ar%SendIndex+ar%SendSize > bufsize) then 423 write(0,'(a,i4,4i7,1x,a)') 'Server Buffer too small ',i,ar%SendIndex,ar%SendSize,ar%SendIndex+ar%SendSize,bufsize,trim(ar%name) 413 424 CALL MPI_Abort (MPI_COMM_WORLD, istat, ierr) 414 425 end if 426 end do 427 end do 428 429 !-- Client to server direction 430 431 bufsize = 8 432 433 !-- First stride, Compute size and set index 434 435 do i=1,Clients(ClientId)%inter_npes 436 aPE => Clients(ClientId)%PEs(i) 437 tag = 300 438 439 do j=1,aPE%Nr_arrays 440 ar => aPE%array_list(j) 441 442 ! Receive Index from client 443 tag = tag+1 444 CALL MPI_Recv (myIndex, 1, MPI_INTEGER, i-1, tag, Clients(ClientId)%inter_comm, MPI_STATUS_IGNORE, ierr) 445 446 if(ar%NrDims == 3) then 447 bufsize = max(bufsize,aPE%NrEle * ar%A_dim(4)) ! 3D 448 else 449 bufsize = max(bufsize,aPE%NrEle) ! 2D 450 end if 451 ar%RecvIndex = myIndex 452 end do 453 454 end do 455 456 !-- Create RMA (One Sided Communication) data buffer 457 !-- The buffer for MPI_Get can be PE local, i.e. it can but must not be part of the MPI RMA window 458 459 CALL PMC_Alloc_mem (base_array_cs, bufsize, base_ptr) 460 Clients(ClientId)%TotalBufferSize = bufsize*wp !Total buffer size in Byte 461 462 CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr) 463 464 !-- Second stride, Set Buffer pointer 465 466 do i=1,Clients(ClientId)%inter_npes 467 aPE => Clients(ClientId)%PEs(i) 468 469 do j=1,aPE%Nr_arrays 470 ar => aPE%array_list(j) 471 ar%RecvBuf = base_ptr 415 472 end do 416 473 end do … … 465 522 end do 466 523 467 CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr) ! buffer is f ull524 CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr) ! buffer is filled 468 525 469 526 return … … 480 537 INTEGER :: ip,ij,istat,ierr,j 481 538 INTEGER :: myIndex 539 INTEGER :: nr 482 540 REAL(wp) :: t1,t2 483 541 TYPE(PeDef),POINTER :: aPE … … 488 546 REAL(wp), POINTER, DIMENSION(:,:) :: data_2d 489 547 REAL(wp), POINTER, DIMENSION(:,:,:) :: data_3d 548 INTEGER :: target_pe 549 INTEGER(kind=MPI_ADDRESS_KIND) :: target_disp 490 550 491 551 t1 = PMC_Time() 492 CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr) ! Wait for MPI_Put from client 493 t2 = PMC_Time() 494 if(present(WaitTime)) WaitTime = t2-t1 552 CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr) ! Wait for client to fill buffer 553 t2 = PMC_Time()-t1 554 if(present(WaitTime)) WaitTime = t2 555 556 ! CALL MPI_Win_fence (0, Clients(ClientId)%win_server_client, ierr) ! Fence might do it, test later 557 CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr) ! Wait for buffer is filled 495 558 496 559 do ip=1,Clients(ClientId)%inter_npes … … 498 561 do j=1,aPE%Nr_arrays 499 562 ar => aPE%array_list(j) 563 564 if(ar%RecvIndex < 0) CYCLE 565 566 if(ar%NrDims == 2) then 567 nr = aPE%NrEle 568 else if(ar%NrDims == 3) then 569 nr = aPE%NrEle*ar%A_dim(4) 570 end if 571 572 buf_shape(1) = nr 573 CALL c_f_pointer(ar%RecvBuf, buf, buf_shape) 574 ! 575 !-- MPI passive target RMA 576 577 if(nr > 0) then 578 target_disp = ar%RecvIndex-1 579 target_pe = ip-1+m_model_npes ! client PEs are located behind server PEs 580 CALL MPI_Win_lock (MPI_LOCK_SHARED , target_pe, 0, Clients(ClientId)%win_server_client, ierr) 581 CALL MPI_Get (buf, nr, MPI_REAL, target_pe, target_disp, nr, MPI_REAL, Clients(ClientId)%win_server_client, ierr) 582 CALL MPI_Win_unlock (target_pe, Clients(ClientId)%win_server_client, ierr) 583 end if 584 500 585 myIndex=1 501 586 if(ar%NrDims == 2) then 502 buf_shape(1) = aPE%NrEle503 CALL c_f_pointer(ar%SendBuf, buf, buf_shape)504 587 CALL c_f_pointer(ar%data, data_2d, ar%A_dim(1:2)) 505 588 do ij=1,aPE%NrEle … … 508 591 end do 509 592 else if(ar%NrDims == 3) then 510 buf_shape(1) = aPE%NrEle*ar%A_dim(4)511 CALL c_f_pointer(ar%SendBuf, buf, buf_shape)512 593 CALL c_f_pointer(ar%data, data_3d, ar%A_dim(1:3)) 513 594 do ij=1,aPE%NrEle … … 519 600 end do 520 601 521 CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr) ! data copy finished, buffer is free for use agein522 523 return524 602 END SUBROUTINE PMC_S_GetData_from_Buffer 525 603
Note: See TracChangeset
for help on using the changeset viewer.