main   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/contrib/mpi/reduce-average.xtm

Implementation

(bind-func main
  (let ((num_elements_per_proc:i32 1000))
    (lambda ()
      (MPI_Init null null)
      (let ((world_size_ptr:i32* (salloc))
            (world_size (begin
                          (MPI_Comm_size MPI_COMM_WORLD world_size_ptr)
                          (pref world_size_ptr 0)))
            (world_rank_ptr:i32* (salloc))
            (world_rank (begin
                          (MPI_Comm_rank MPI_COMM_WORLD world_rank_ptr)
                          (pref world_rank_ptr 0)))
            (number:i32* (salloc)))
        (letz ((rand_nums:float* (zalloc num_elements_per_proc))
               (local_sum 0.0)
               (global_sum_ptr:float* (salloc))
               (i 0))
          ;; Create a random array of elements on all processes.
          (dotimes (i num_elements_per_proc)
            (pset! rand_nums i (random)))
          ;; Sum the numbers locally
          (dotimes (i num_elements_per_proc)
            (set! local_sum (+ local_sum (pref rand_nums i))))
          ;; Print the random numbers on each process
          (printf "Local sum for process %d: %f, avg = %f\n"
                  world_rank (convert local_sum double) (/ (convert local_sum double) (convert num_elements_per_proc double)));
          ;; Reduce all of the local sums into the global sum
          (MPI_Reduce (let ((ptr:float* (salloc)))
                        (pset! ptr 0 local_sum)
                        (convert ptr i8*))
                      (convert global_sum_ptr i8*)
                      1 MPI_FLOAT MPI_SUM 0 MPI_COMM_WORLD)
          ;; Print the result
          (if (= world_rank 0)
              (printf "Total sum = %f, avg = %f\n"
                      (convert (pref global_sum_ptr 0) double) (convert (/ (pref global_sum_ptr 0) (convert (* world_size num_elements_per_proc))) double)))
          (MPI_Barrier MPI_COMM_WORLD)
          (MPI_Finalize))))))


Back to Index

Similar Entries

  • _glib_main_loop_call    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/slideshow.xtm
  • _glib_main_loop_call    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo_multi.xtm
  • _glib_main_loop_call    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo.xtm
  • _gst_main_loop_call    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/mediaplayer.xtm
  • cerberus_main_cc    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/cerberus_midi.xtm
  • clock_scheduler_main_callback    xtlang    /digego/extempore/tree/v0.8.9/libs/core/scheduler.xtm
  • decompose_domain    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/mpi/random-walk.xtm
  • get_main_frame    xtlang    /digego/extempore/tree/v0.8.9/libs/external/cef/cef.xtm
  • glib-main-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/slideshow.xtm
  • glib-main-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo_multi.xtm
  • glib_main_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo.xtm
  • gst-main-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/mediaplayer.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/core/fasta_lang_shootout.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/core/nbody_lang_shootout.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/opencl.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/80211.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/mpi/mpitest.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/mpi/send-recv.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/mpi/random-walk.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/mpi/hello-world.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/mpi/ping-pong.xtm
  • main    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/extempore-fortran/simulation.xtm
  • mainLoop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/horde3d_knight.xtm
  • mainLoop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/bullet.xtm
  • main_cc    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue_midi.xtm
  • main_gain    xtlang    /digego/extempore/tree/v0.8.9/examples/sharedsystem/audiosetup.xtm
  • main_reverb    xtlang    /digego/extempore/tree/v0.8.9/examples/sharedsystem/audiosetup.xtm
  • run_main_event_loop    xtlang    /digego/extempore/tree/v0.8.9/libs/core/scheduler.xtm
  • set_dl_main    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/dlogue.xtm