/*****************************************************************************\ * test7.2.prog.c - Test of basic PMI library functionality ***************************************************************************** * Copyright (C) 2005-2006 The Regents of the University of California. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Written by Morris Jette * CODE-OCEC-09-009. All rights reserved. * * This file is part of Slurm, a resource management program. * For details, see . * Please also read the included file: DISCLAIMER. * * Slurm is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * Slurm is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along * with Slurm; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. \*****************************************************************************/ #include #include #include #include #if 0 /* Typical MPICH2 use */ # define BARRIER_CNT 0 # define PUTS_PER_BARRIER 0 #else /* Typical MVAPICH2 use * * Adjust job time limit and timeout in test7.2 as needed * for large values. */ # define BARRIER_CNT 4 # define PUTS_PER_BARRIER 0 #endif #define _DEBUG 0 #define OFFSET_1 1234 #define OFFSET_2 5678 int main (int argc, char **argv) { int i, j, rc; int nprocs, procid; int clique_size, *clique_ranks = NULL; char *jobid_ptr, *nprocs_ptr, *procid_ptr; int pmi_rank, pmi_size, kvs_name_len, key_len, val_len; PMI_BOOL initialized; char *key, *val, *kvs_name; struct timeval tv1, tv2; long delta_t; char tv_str[20]; gettimeofday(&tv1, NULL); /* Get process count and our id from environment variables */ jobid_ptr = getenv("SLURM_JOB_ID"); nprocs_ptr = getenv("SLURM_NPROCS"); procid_ptr = getenv("SLURM_PROCID"); if (jobid_ptr == NULL) { printf("WARNING: PMI test not run under Slurm\n"); nprocs = 1; procid = 0; } else if ((nprocs_ptr == NULL) || (procid_ptr == NULL)) { printf("FAILURE: Slurm environment variables not set\n"); exit(1); } else { nprocs = atoi(nprocs_ptr); procid = atoi(procid_ptr); } /* Validate process count and our id */ if ((nprocs < 1) || (nprocs > 9999)) { printf("FAILURE: Invalid nprocs %s\n", nprocs_ptr); exit(1); } if ((procid < 0) || (procid > 9999)) { printf("FAILURE: Invalid procid %s\n", procid_ptr); exit(1); } /* Get process count and size from PMI and validate */ if ((rc = PMI_Init(&i)) != PMI_SUCCESS) { printf("FAILURE: PMI_Init: %d\n", rc); exit(1); } initialized = PMI_FALSE; if ((rc = PMI_Initialized(&initialized)) != PMI_SUCCESS) { printf("FAILURE: PMI_Initialized: %d\n", rc); exit(1); } if (initialized != PMI_TRUE) { printf("FAILURE: PMI_Initialized returned false\n"); exit(1); } if ((rc = PMI_Get_rank(&pmi_rank)) != PMI_SUCCESS) { printf("FAILURE: PMI_Get_rank: %d\n", rc); exit(1); } #if _DEBUG printf("PMI_Get_rank = %d\n", pmi_rank); #endif if ((rc = PMI_Get_size(&pmi_size)) != PMI_SUCCESS) { printf("FAILURE: PMI_Get_size: %d, task %d\n", rc, pmi_rank); exit(1); } #if _DEBUG printf("PMI_Get_size = %d\n", pmi_size); #endif if (pmi_rank != procid) { printf("FAILURE: Rank(%d) != PROCID(%d)\n", pmi_rank, procid); exit(1); } if (pmi_size != nprocs) { printf("FAILURE: Size(%d) != NPROCS(%d), task %d\n", pmi_size, nprocs, pmi_rank); exit(1); } if ((rc = PMI_Get_clique_size(&clique_size)) != PMI_SUCCESS) { printf("FAILURE: PMI_Get_clique_size: %d, task %d\n", rc, pmi_rank); exit(1); } clique_ranks = malloc(sizeof(int) * clique_size); if ((rc = PMI_Get_clique_ranks(clique_ranks, clique_size)) != PMI_SUCCESS) { printf("FAILURE: PMI_Get_clique_ranks: %d, task %d\n", rc, pmi_rank); exit(1); } #if _DEBUG for (i=0; i