Ejemplo n.º 1
0
// buf_size must be a mulitple of 8 bytes
QBUF_ID *qbufCreate(long buf_num, long buf_size, long policy)
{
  QBUF_ID *qbuf_id_tmp;
  static long init=0;
  long i;

  if ((policy & QBUF_ALLOCATION_MASK) != QBUF_FIFO_ALLOCATION_POLICY) {
    PRINT_FATAL("Allocation policies other than a first-in first-out queue have not been implemented yet.\n");
  }

  qbuf_id_tmp = malloc(sizeof(QBUF_ID));

  if (qbuf_id_tmp == NULL) {
    PRINT_FATAL("Error: qbuf_id malloc failed");
  }

  qbuf_id_tmp->base_addr = malloc(buf_num*buf_size);
  if (qbuf_id_tmp->base_addr == NULL) {
    PRINT_FATAL("Error: qbuf array malloc failed");
  }
  qbuf_id_tmp->num_buffers = buf_num;
  qbuf_id_tmp->buffer_size = buf_size;
  qbuf_id_tmp->policy = policy;

  qbuf_id_tmp->index_p = malloc((buf_num+1)*sizeof(long));
  if (qbuf_id_tmp->index_p == NULL) {
    PRINT_FATAL("Error: qbuf index malloc failed");
  }
  qbuf_id_tmp->index_head=0;
  qbuf_id_tmp->index_tail=buf_num;
  for(i=0; i<buf_num; i++) {
    (qbuf_id_tmp->index_p)[i] = (long)(qbuf_id_tmp->base_addr + i * buf_size);
  }
  (qbuf_id_tmp->index_p)[buf_num] = -1;

  return qbuf_id_tmp;
}
Ejemplo n.º 2
0
void
mergeGatherDescriptions(GatherDescription *gd, GatherDescription *gds, int n)
{
  int ni=0, nsi=0;
  for(int i=0; i<n; i++) {
    ni += gds[i].nIndices;
    nsi += gds[i].nSendIndices;
    if(gds[i].myRank!=gds[0].myRank) {
      BEGIN_FATAL;
      PRINT_FATAL("ranks don't match: gds[%i].myRank(%i)!=gds[0].myRank(%i)\n",
		  i, gds[i].myRank, gds[0].myRank);
      END_FATAL;
    }
  }
  int *sr = myalloc(ni*sizeof(int));
  int *si = myalloc(ni*sizeof(int));
  ni = 0;
  for(int i=0; i<n; i++) {
    for(int j=0; j<gds[i].nIndices; j++) {
      sr[ni] = gds[i].srcRanks[j];
      si[ni] = gds[i].srcIndices[j];
      ni++;
    }
  }
  int *ssi = myalloc(nsi*sizeof(int));
  int *sdr = myalloc(nsi*sizeof(int));
  int *sdi = myalloc(nsi*sizeof(int));
  nsi = 0;
  for(int i=0; i<n; i++) {
    for(int j=0; j<gds[i].nSendIndices; j++) {
      ssi[nsi] = gds[i].sendSrcIndices[j];
      sdr[nsi] = gds[i].sendDestRanks[j];
      sdi[nsi] = gds[i].sendDestIndices[j];
      nsi++;
    }
  }
  gd->myRank = gds[0].myRank;
  gd->nIndices = ni;
  gd->srcRanks = sr;
  gd->srcIndices = si;
  gd->nSendIndices = nsi;
  gd->sendSrcIndices = ssi;
  gd->sendDestRanks = sdr;
  gd->sendDestIndices = sdi;
}