GlobalArrays/ga

Wrong output

Closed this issue · 2 comments

Hi GA Community,
I created a simple code (below) to test GA on my Mac. It gives me wrong output on rank 0. Basically, I only read each local data with a ghost layer. Could some give my some hint where I did wrong? Thanks.

Bests,
Bin

Output

mpirun -n 16 ./ga-test
Running on 16 processors

Ater create A & B:  A: ga_rank=0, dist_lo=(0,0), dist_hi=(3,3)
Read on rank 0, lo = (0, 0), hi=(4, 4)
 Read on rank 1, lo = (0, 3), hi=(4, 8)
 Data read on rank 0:  0,  1,  2,  3,  1,  4,  5,  6,  7,  5,  8,  9,  10,  11,  9,  12,  13,  14,  15,  13,  4,  5,  6,  7,  5,
Data read on rank 1:  3,  1,  2,  3,  4,  2,  5,  6,  7,  8,  6,  9,  10,  11,  12,  10,  13,  14,  15,  16,  7,  5,  6,  7,  8,  6,  6,  -1342177280,  1702909489,  32700,

Source code:

```cpp
#include <mpi.h>
#include "ga.h"
#include <assert.h> /* assert */
#include <stdlib.h>

#define SIZE 16
#define CHUNK 4
#define READ_GHOST 1

int main(int argc, char **argv)
{
  MPI_Init(&argc, &argv);
  GA_Initialize();

  int me = GA_Nodeid();
  int nproc = GA_Nnodes();
  if (me == 0)
  {
    printf("Running on %d processors\n\n", nproc);
  }

  int ndim = 2;

  int64_t dims[2];
  dims[0] = SIZE;
  dims[1] = SIZE;

  int64_t chunk[2];
  chunk[0] = CHUNK;
  chunk[1] = CHUNK;

  char *array_name = (char *)"array A";
  int g_A = NGA_Create64(C_INT, ndim, dims, array_name, chunk);

  int64_t A_dist_lo[2], A_dist_hi[2];
  NGA_Distribution64(g_A, me, &(A_dist_lo[0]), &(A_dist_hi[0]));
  if (!me)
    printf("Ater create A & B:  A: ga_rank=%d, dist_lo=(%lld,%lld), dist_hi=(%lld,%lld)\n", me, 
  A_dist_lo[0], A_dist_lo[1], A_dist_hi[0], A_dist_hi[1]);
  fflush(stdout);
  int64_t A_read_lo[2], A_read_hi[2], A_write_lo[2], A_write_hi[2], A_rw_ld[2];
  int *A_read_data, *A_write_data;
  int A_read_data_size = 1, A_write_data_size = 1;
  for (int j = 0; j < ndim; j++)
  {
    if (A_dist_hi[j] + 1 < SIZE)
    {
      A_read_hi[j] = A_dist_hi[j] + 1;
    }
    else
    {
      A_read_hi[j] = A_dist_hi[j];
    }

    if (A_dist_lo[j] - 1 >= 0)
    {
      A_read_lo[j] = A_dist_lo[j] - 1;
    }
    else
    {
      A_read_lo[j] = A_dist_lo[j];
    }
    A_write_hi[j] = A_dist_hi[j];
    A_write_lo[j] = A_dist_lo[j];

    A_read_data_size = A_read_data_size * (A_read_hi[j] - A_read_lo[j] + 1);
    A_write_data_size = A_write_data_size * (A_write_hi[j] - A_write_lo[j] + 1);
  }

  A_write_data = (int *)malloc(A_write_data_size * sizeof(int));
  A_read_data = (int *)malloc(A_read_data_size * sizeof(int));

  for (int i = 0; i < A_write_data_size; i++)
  {
    A_write_data[i] = i + me;
  }
  //Write Data to A;
  A_rw_ld[0] = A_dist_hi[0] - A_dist_lo[0] + 1;
  A_rw_ld[1] = A_dist_hi[1] - A_dist_lo[1] + 1;

  NGA_Put64(g_A, A_write_lo, A_write_hi, A_write_data, A_rw_ld);
  GA_Sync();

  if (me <= 1)
  {
    printf("Read on rank %d, lo = (%lld, %lld), hi=(%lld, %lld) \n ", me, A_read_lo[0], A_read_lo[1], A_read_hi[0], A_read_hi[1]);
  }

  A_rw_ld[0] = A_dist_hi[0] - A_dist_lo[0] + 2;
  A_rw_ld[1] = A_dist_hi[1] - A_dist_lo[1] + 2;
  NGA_Get64(g_A, A_read_lo, A_read_hi, A_read_data, A_rw_ld);
  if (me <= 1)
  {
    printf("Data read on rank %d: ", me);
    for (int k = 0; k < A_read_data_size; k++)
      printf(" %d, ", A_read_data[k]);
    printf("\n");
    fflush(stdout);
  }

  free(A_read_data);
  free(A_write_data);

  GA_Destroy(g_A);
  GA_Terminate();
  MPI_Finalize();
}

Also, if I run it with single process, another error comes up (the output data also gives wrong result):

mpirun -n 1 ./ga-test
Running on 1 processors

Ater create A & B: A: ga_rank=0, dist_lo=(0,0), dist_hi=(15,15)
Read on rank 0, lo = (0, 0), hi=(15, 15)
Data read on rank 0: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1161764912, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32751, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 14721295, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, -1697629288, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, -1161764096, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 32751, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 551592223, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, -1697629288, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 14721295, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1697629288, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 14721295, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, -1697629288, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 14721295, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, -1697629288, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 14721295, 240,

===================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= PID 51933 RUNNING AT dbinMac
= EXIT CODE: 6
= CLEANING UP REMAINING PROCESSES
= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES

YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Abort trap: 6 (signal 6)
This typically refers to a problem with your application.
Please see the FAQ page for debugging suggestions

closing due to inactivity, feel free to re-open if needed