ccm_scatterv

CCM scatter with variable amounts of data.

Routine:

ccm_scatterv

Purpose:

Send different amounts of data from one task to all other tasks in a parallel application. By default, the zeroth task in the parallel application sends the data. Xout is overwritten on all tasks.

Minimal calling sequence:

call ccm_scatterv(xin,xout,to_send)

Required Arguments:

xin :: integer, real, double precision, complex, logical, character array,intent (in)
The values in xin will be distributed from one task to every other task in the parallel application.
xout :: integer, real, double precision, complex, logical, character array,intent (out)
The values distributed to each task will be placed in xout.
to_send :: integer, rank one array of size equal to the number of tasks in the parallel application,intent (in)
The number of values sent from a single task to each other tasks.

Call with all Optional Arguments:

call ccm_scatterv(xin,xout,to_send,offset,root,the_err)
offset :: integer, rank one array of size equal to the number of tasks in the parallel application,intent (in)
Location from where the data to be sent for a particular task is obtained, relative to the beginning of xin. If not given, then the values are sent from xin in the normal order.
root :: integer,intent (in)
The number of the task that sends the data, defaults to the root task of the parallel application.
the_err :: integer, intent (out)
Error code 0 = success, != 0 failure.
See Specifying Optional Arguments for the syntax for using optional arguments.

Notes:

Xin and xout can be any intrinsic Fortran data type: integer, real, double precision, complex, logical or, character. Xin must be an array. Xout can be a scaler or an array.

First example:


program ccm_scatterv_x1
    use ccm 
    implicit none
    integer :: myid,numprocs,igot,i,j
    character, allocatable :: xin(:), xout(:)
    integer, allocatable :: to_send(:)
    integer :: to_get
    call ccm_init(myid,numprocs) 
    if(myid .eq. 0)then
        allocate(to_send(0:numprocs-1))
        do i=0,numprocs-1
           to_send(i)=myid+i
        enddo
    else
        allocate(to_send(0))
    endif
    call ccm_scatter(to_send,to_get) 
    allocate(xout(to_get))
    if(myid .eq. 0)then
        allocate(xin(sum(to_send)))
        do i=1,size(xin)
            xin(i)=char(ichar('a')+mod(i-1,26))
        enddo
    endif
    call ccm_scatterv(xin,xout,to_send) 
    write(*,"("" i= "",i4,"" xout= "",20a1)")myid,xout
    call ccm_close() 
end program

Example output on 4 processors


[ccm_host:~/ccm/source]% ccm_scatterv_x1
 i=    0 xout= 
 i=    2 xout= bc
 i=    1 xout= a
 i=    3 xout= def
[ccm_host:~/ccm/source] % 

The call to ccm_init initializes the communication package. Task 0 allocates and fills the to_send array, that is, how many values will be send to each task. Each task is told how many values to expect by scattering this array into to_get. Space is allocated for the output. On task 0 will fill the array xin with characters. The characters are scattered with ccm_scatterv and each task prints what it has received. Ccm_close is called to close the package.

Second example:


program ccm_scatterv_x2
    use ccm
    implicit none
    integer :: myid,numprocs,igot,i,j
    character, allocatable :: xin(:),xout(:)
    integer ,allocatable :: to_send(:),offset(:)
    integer :: to_get
    call ccm_init(myid,numprocs)
    allocate(to_send(numprocs),offset(numprocs))
    to_send=4
    to_get=4
    if(myid .eq. 0)then
        allocate(xin(sum(to_send)))
        do i=1,size(xin)
            xin(i)=char(ichar('a')+mod(i-1,26))
        enddo
        do i=1,numprocs
           offset(i)=(numprocs-i)*to_send(1)
        enddo
        write(*,*)"send array is: ",xin
    endif
    call ccm_barrier(1.0)
    allocate(xout(to_get))
    call ccm_scatterv(xin,xout,to_send,offset)
    write(*,"("" i= "",i4,"" xout= "",8a1)")myid,xout   
    call ccm_close()
end program

Example output on 4 processors


[ccm_host:~/ccm/source]% ccm_scatterv_x2
 send array is: abcdefghijklmnop
 i=    0 xout= mnop
 i=    2 xout= efgh
 i=    3 xout= abcd
 i=    1 xout= ijkl
[ccm_host:~/ccm/source] % 

The call to ccm_init initializes the communication package. The count and offset arrays are allocated. Each task will receive 4 values. Task 0 fills an array with 16 characters. The program scatters values in reverse order by filling the offset array as shown. Task 3 gets characters from the beginning of the array and task 0 from the end. The program sends the values using ccm_scatterv. They are printed with task 3 writing the beginning of the alphabet. The call to ccm_close closes the communication package.

Error conditions:


If the error checking level is set to ccm_checksize the following error condition(s) are checked: These conditions may lead to a Underling communications error if not detected.
Back to API and user's guide