File: test_mpi2.c

package info (click to toggle)
openmx 3.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 325,856 kB
  • ctags: 3,575
  • sloc: ansic: 152,655; f90: 2,080; python: 876; makefile: 675; sh: 25; perl: 18
file content (68 lines) | stat: -rw-r--r-- 1,290 bytes parent folder | download | duplicates (4)
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/times.h>
#include "mpi.h"
#include "openmx_common.h"

#define asize1  819200  // 819200

static void dtime(double *t);

int main(int argc, char *argv[]) 
{

  int numprocs,myid,ID,count,tag,i,j,k;

  double *SndA;
  double *RcvA;
  double TStime,TEtime;

  MPI_Status stat;
  MPI_Request request;

  MPI_Init(&argc,&argv);
  MPI_Comm_size(mpi_comm_level1,&numprocs);
  MPI_Comm_rank(mpi_comm_level1,&myid);

  SndA = (double*)malloc(sizeof(double)*asize1);
  RcvA = (double*)malloc(sizeof(double)*asize1);

  printf("numprocs=%2d myid=%2d\n",numprocs,myid);

  tag = 999;
 
  MPI_Barrier(mpi_comm_level1);
  dtime(&TStime);

  for (ID=0; ID<numprocs; ID++){
    if (ID!=myid){
      MPI_Isend(&SndA[0], asize1, MPI_DOUBLE, ID, tag, mpi_comm_level1, &request);
      MPI_Recv( &RcvA[0], asize1, MPI_DOUBLE, ID, tag, mpi_comm_level1, &stat);
      MPI_Wait(&request,&stat);
    }
  }

  MPI_Barrier(mpi_comm_level1);
  dtime(&TEtime);

  printf("elapsed time = %15.10f\n",TEtime-TStime);

  MPI_Finalize();
}


void dtime(double *t)
{

  // real time
  struct timeval timev;
  gettimeofday(&timev, NULL);
  *t = timev.tv_sec + (double)timev.tv_usec*1e-6;

}