ccm_bcast

CCM broadcast

Routine:

ccm_bcast

Purpose:

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

Minimal calling sequence:

call ccm_bcast(x)

Required Arguments:

x :: integer, real, double precision, complex, logical, character (scaler or array),intent (inout)
The values in x will be sent from one task to all other tasks in a parallel application. By default, the zeroth task in the parallel application sends the data. X is overwritten on all other tasks.

Call with all Optional Arguments:

call ccm_bcast(x,root,the_err)
root :: integer,intent (in)
The number of the task that sends the data, defaults to the zeroth 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:

X can be any intrinsic Fortran data type: integer, real, double precision, complex, logical or, character. It can be a scaler or an array. If X is an array then it must be the same size for all tasks. Also, if x is an array, the entire array will be broadcast.

First example:


program ccm_bcast_x1
    use ccm
    implicit none
    integer time_info_array(8),hour,min,sec,millisec,ierr
    real local_time,global_time
    call ccm_init()
    call date_and_time(values=time_info_array)
    hour=time_info_array(5)
    min=time_info_array(6)
    sec=time_info_array(7)
    millisec=time_info_array(8)
    local_time=(hour*60+min)*60+sec+millisec/1000.0
    global_time=local_time
    call ccm_bcast(global_time)
    write(*,*)"time difference from the root process = ",&
               global_time-local_time
    call ccm_bcast(time_info_array)
    write(*,fmt="(""root and my time "",2(2x,i2.2,"":"",i2.2,"":"",i2.2,""."",i3.3))") &
        time_info_array(5),time_info_array(6),time_info_array(7),time_info_array(8), &
        hour              ,min               ,sec               ,millisec
    call ccm_close()
end program

Example output on 4 processors


[ccm_host:~/ccm/source]% ccm_bcast_x1
 time difference from the root process =   0.000000
root and my time   10:48:32.286  10:48:32.286
 time difference from the root process =  -0.054
root and my time   10:48:32.286  10:48:32.340
 time difference from the root process =  -101.406
root and my time   10:48:32.286  10:50:13.691
 time difference from the root process =  -7.31641
root and my time   10:48:32.286  10:48:39.602
[ccm_host:~/ccm/source] % 

The call to ccm_init initializes the communication package. The time is then obtained and converted to a real value, local_time and then copied to global_time. The root task broadcasts global_time to all other tasks. All tasks now have the global_time from task zero. Each task prints the difference between global_time and local_time. The root task then broadcasts its time_info_array to the other tasks. All tasks then print the time_info_array and values for hours, minutes, seconds, and milliseconds. The call to ccm_close closes the communication package.

Second Example:


program ccm_bcast_x2
    use ccm
    implicit none
    integer :: ids(2)
    integer :: myid,numprocs,root,the_err,to_send
    call ccm_init(myid,numprocs)
    ids=myid
    root=2
    to_send=1
    call ccm_bcast(ids(1:1),root,the_err)
    write(*,*)"root id= ",ids(1)," my id= ",ids(2)
    call ccm_close()
end program

Example output on 4 processors


[ccm_home:~/ccm/source] % ccm_bcast_x2
 root id=   2  my id=   0
 root id=   2  my id=   2
 root id=   2  my id=   1
 root id=   2  my id=   3
[ccm_home:~/ccm/source] % 

The call to ccm_init initializes the communication package. The 2 elements of the array ids are set to the task id, 0-3. The root task is set to 2 and ccm_bcast is called to send 1 value from the array ids. Each task gets a single value that replaces the first element of ids. The two elements of ids are printed, the root task id and "myid". 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