<commit_before>#include "ghost/config.h"
#include "ghost/core.h"
#include "ghost/types.h"
#include "ghost/util.h"
#include "ghost/context.h"
#include "ghost/sparsemat.h"
#include "ghost/locality.h"
#include "ghost/bincrs.h"
#include "ghost/matrixmarket.h"
#include "ghost/log.h"


ghost_error_t ghost_context_create(ghost_context_t **context, ghost_gidx_t gnrows, ghost_gidx_t gncols, ghost_context_flags_t context_flags, void *matrixSource, ghost_sparsemat_src_t srcType, ghost_mpi_comm_t comm, double weight) 
{
    if (weight < 0) {
        ERROR_LOG("Negative weight");
        return GHOST_ERR_INVALID_ARG;
    }
           
    int nranks, me, i;
    ghost_error_t ret = GHOST_SUCCESS;
    
    ghost_lidx_t *target_rows = NULL;
    char *tmpval = NULL;
    ghost_gidx_t *tmpcol = NULL;
    
    GHOST_CALL_GOTO(ghost_malloc((void **)context,sizeof(ghost_context_t)),err,ret);
    (*context)->flags = context_flags;
    (*context)->mpicomm = comm;
    (*context)->perm_local = NULL;
    (*context)->perm_global = NULL;
    (*context)->wishes   = NULL;
    (*context)->dues     = NULL;
    (*context)->hput_pos = NULL;

    
    GHOST_CALL_GOTO(ghost_nrank(&nranks, (*context)->mpicomm),err,ret);
    GHOST_CALL_GOTO(ghost_rank(&me, (*context)->mpicomm),err,ret);

    (*context)->cu_duelist = NULL;
    
    GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->wishlist,nranks*sizeof(ghost_lidx_t *)),err,ret); 
    GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->duelist,nranks*sizeof(ghost_lidx_t *)),err,ret);
    GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->wishes,nranks*sizeof(ghost_lidx_t)),err,ret); 
    GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->dues,nranks*sizeof(ghost_lidx_t)),err,ret); 
#ifdef GHOST_HAVE_CUDA
    ghost_type_t type;
    ghost_type_get(&type);
    if (type == GHOST_TYPE_CUDA) {
        GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->cu_duelist,nranks*sizeof(ghost_lidx_t *)),err,ret);
    }
#endif

    for (i=0; i<nranks; i++){
        (*context)->wishes[i] = 0;
        (*context)->dues[i] = 0;
        (*context)->wishlist[i] = NULL;
        (*context)->duelist[i] = NULL;
        (*context)->cu_duelist[i] = NULL;
    }

    if (!((*context)->flags & GHOST_CONTEXT_DIST_NZ)) {
        (*context)->flags |= (ghost_context_flags_t)GHOST_CONTEXT_DIST_ROWS;
    }

    if ((gnrows == 0) || (gncols == 0)) {
        if (srcType == GHOST_SPARSEMAT_SRC_FUNC) {
            ERROR_LOG("The correct dimensions have to be given if the sparsemat source is a function!");
            return GHOST_ERR_INVALID_ARG;
        } else if (srcType == GHOST_SPARSEMAT_SRC_FILE) {<commit_msg>bug fix: do not access cu_duelist unless CUDA is available<commit_after>#include "ghost/config.h"
#include "ghost/core.h"
#include "ghost/types.h"
#include "ghost/util.h"
#include "ghost/context.h"
#include "ghost/sparsemat.h"
#include "ghost/locality.h"
#include "ghost/bincrs.h"
#include "ghost/matrixmarket.h"
#include "ghost/log.h"


ghost_error_t ghost_context_create(ghost_context_t **context, ghost_gidx_t gnrows, ghost_gidx_t gncols, ghost_context_flags_t context_flags, void *matrixSource, ghost_sparsemat_src_t srcType, ghost_mpi_comm_t comm, double weight) 
{
    if (weight < 0) {
        ERROR_LOG("Negative weight");
        return GHOST_ERR_INVALID_ARG;
    }
           
    int nranks, me, i;
    ghost_error_t ret = GHOST_SUCCESS;
    
    ghost_lidx_t *target_rows = NULL;
    char *tmpval = NULL;
    ghost_gidx_t *tmpcol = NULL;
    
    GHOST_CALL_GOTO(ghost_malloc((void **)context,sizeof(ghost_context_t)),err,ret);
    (*context)->flags = context_flags;
    (*context)->mpicomm = comm;
    (*context)->perm_local = NULL;
    (*context)->perm_global = NULL;
    (*context)->wishes   = NULL;
    (*context)->dues     = NULL;
    (*context)->hput_pos = NULL;

    
    GHOST_CALL_GOTO(ghost_nrank(&nranks, (*context)->mpicomm),err,ret);
    GHOST_CALL_GOTO(ghost_rank(&me, (*context)->mpicomm),err,ret);

    (*context)->cu_duelist = NULL;
    
    GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->wishlist,nranks*sizeof(ghost_lidx_t *)),err,ret); 
    GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->duelist,nranks*sizeof(ghost_lidx_t *)),err,ret);
    GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->wishes,nranks*sizeof(ghost_lidx_t)),err,ret); 
    GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->dues,nranks*sizeof(ghost_lidx_t)),err,ret); 
#ifdef GHOST_HAVE_CUDA
    ghost_type_t type;
    ghost_type_get(&type);
    if (type == GHOST_TYPE_CUDA) {
        GHOST_CALL_GOTO(ghost_malloc((void **)&(*context)->cu_duelist,nranks*sizeof(ghost_lidx_t *)),err,ret);
    }
#endif

    for (i=0; i<nranks; i++){
        (*context)->wishes[i] = 0;
        (*context)->dues[i] = 0;
        (*context)->wishlist[i] = NULL;
        (*context)->duelist[i] = NULL;
#ifdef GHOST_HAVE_CUDA
        (*context)->cu_duelist[i] = NULL;
#endif
    }

    if (!((*context)->flags & GHOST_CONTEXT_DIST_NZ)) {
        (*context)->flags |= (ghost_context_flags_t)GHOST_CONTEXT_DIST_ROWS;
    }

    if ((gnrows == 0) || (gncols == 0)) {
        if (srcType == GHOST_SPARSEMAT_SRC_FUNC) {
            ERROR_LOG("The correct dimensions have to be given if the sparsemat source is a function!");
            return GHOST_ERR_INVALID_ARG;
        } else if (srcType == GHOST_SPARSEMAT_SRC_FILE) {
{'fraction_non_alphanumeric': 0.1576382380506092, 'fraction_numerical': 0.0022492970946579195, 'mean_word_length': 4.11601150527325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2522316', 'n_tokens_mistral': 2069, 'n_tokens_neox': 2017, 'n_words': 314}