lib/mpi_helper.c
void update_mpi_manager(struct meta_neural_net *meta, mpi_manager *manager,
                        unsigned int training_samples, unsigned int testing_samples,
                        jcky_cli *cli, unsigned char *err) {
    *err = 0;
    const unsigned char memory_layout = meta->memory_layout;
    const unsigned short int child_procs_or_one = (manager->rank == 0) ? manager->child_procs : 1;
    unsigned short int nn_number_of_requests =
        ((meta->memory_layout == (unsigned char)JCKY_CONTIGUOUS_LAYOUT_ID ) ? 1 : ((meta->number_of_hidden_layers + 1) * 2))
        * child_procs_or_one;

    if (memory_layout == (unsigned char)JCKY_CONTIGUOUS_LAYOUT_ID) {
        const unsigned long int container_len = meta->nns[JCKY_NN_BASE].container_len;
        unsigned long int elements_per_request = container_len;
        if (meta->num_blocks) {
            if (container_len % meta->num_blocks == 0) {
                elements_per_request = container_len / meta->num_blocks;
            }
            else {
                elements_per_request = (container_len / meta->num_blocks) + 1;
            }
        }
        else if (meta->block_size) {
            elements_per_request = meta->block_size / sizeof(nn_type);
        }

        manager->elements_per_request = (int)((elements_per_request > INT_MAX) ? INT_MAX : elements_per_request);
        manager->requests_per_transaction = (container_len % manager->elements_per_request == 0) ?
                                            (container_len / manager->elements_per_request) :
                                            (container_len / manager->elements_per_request) + 1;
        manager->elements_in_last_request = (int)(container_len - (manager->elements_per_request * (manager->requests_per_transaction - 1)));
        nn_number_of_requests *= manager->requests_per_transaction;
        // printf("Elements per request: %u\n", manager->elements_per_request);
        // printf("Requests per transaction: %u\n", manager->requests_per_transaction);
        // printf("Elements in last request: %u\n", manager->elements_in_last_request);
        // printf("Number of requests: %u\n", nn_number_of_requests);
    }

    manager->neural_net = create_request_manager(nn_number_of_requests);
    manager->sequence = create_request_manager(child_procs_or_one);

    if (cli->verbose && manager->master) printf("\nCreating sample managers:\n");
    manager->training_samples = create_sample_manager(
        training_samples, meta->batch_size, manager, TRAINING_DATA, cli, err);
    manager->testing_samples = create_sample_manager(
        testing_samples, meta->batch_size, manager, TESTING_DATA, cli, err);

    manager->send_nn_async_func = JCKY_SEND_NN_ASYNC_FUNCS[memory_layout];
    manager->recv_nn_async_func = JCKY_RECV_NN_ASYNC_FUNCS[memory_layout];
}
// TODO:
//   - Make sure types are correct for world size and rank
//   - Use destructor for this
//   - Use a data manager
Make sure types are correct for world size and rank
Use destructor for this
Use a data manager
Make sure types are correct for world size and rank Use destructor for this Use a data manager
void update_mpi_manager(struct meta_neural_net *meta, mpi_manager *manager,
                        unsigned int training_samples, unsigned int testing_samples,
                        jcky_cli *cli, unsigned char *err) {
    *err = 0;
    const unsigned char memory_layout = meta->memory_layout;
    const unsigned short int child_procs_or_one = (manager->rank == 0) ? manager->child_procs : 1;
    unsigned short int nn_number_of_requests =
        ((meta->memory_layout == (unsigned char)JCKY_CONTIGUOUS_LAYOUT_ID ) ? 1 : ((meta->number_of_hidden_layers + 1) * 2))
        * child_procs_or_one;
    if (memory_layout == (unsigned char)JCKY_CONTIGUOUS_LAYOUT_ID) {
        const unsigned long int container_len = meta->nns[JCKY_NN_BASE].container_len;
        unsigned long int elements_per_request = container_len;
        if (meta->num_blocks) {
            if (container_len % meta->num_blocks == 0) {
                elements_per_request = container_len / meta->num_blocks;
            }
            else {
                elements_per_request = (container_len / meta->num_blocks) + 1;
            }
        }
        else if (meta->block_size) {
            elements_per_request = meta->block_size / sizeof(nn_type);
        }
        manager->elements_per_request = (int)((elements_per_request > INT_MAX) ? INT_MAX : elements_per_request);
        manager->requests_per_transaction = (container_len % manager->elements_per_request == 0) ?
                                            (container_len / manager->elements_per_request) :
                                            (container_len / manager->elements_per_request) + 1;
        manager->elements_in_last_request = (int)(container_len - (manager->elements_per_request * (manager->requests_per_transaction - 1)));
        nn_number_of_requests *= manager->requests_per_transaction;
    }
    manager->neural_net = create_request_manager(nn_number_of_requests);
    manager->sequence = create_request_manager(child_procs_or_one);
    if (cli->verbose && manager->master) printf("\nCreating sample managers:\n");
    manager->training_samples = create_sample_manager(
        training_samples, meta->batch_size, manager, TRAINING_DATA, cli, err);
    manager->testing_samples = create_sample_manager(
        testing_samples, meta->batch_size, manager, TESTING_DATA, cli, err);
    manager->send_nn_async_func = JCKY_SEND_NN_ASYNC_FUNCS[memory_layout];
    manager->recv_nn_async_func = JCKY_RECV_NN_ASYNC_FUNCS[memory_layout];
}
void update_mpi_manager ( struct meta_neural_net * meta , mpi_manager * manager , unsigned int training_samples , unsigned int testing_samples , jcky_cli * cli , unsigned char * err ) { * err = 0 ; const unsigned char memory_layout = meta -> memory_layout ; const unsigned short int child_procs_or_one = ( manager -> rank == 0 ) ? manager -> child_procs : 1 ; unsigned short int nn_number_of_requests = ( ( meta -> memory_layout == ( unsigned char ) JCKY_CONTIGUOUS_LAYOUT_ID ) ? 1 : ( ( meta -> number_of_hidden_layers + 1 ) * 2 ) ) * child_procs_or_one ; if ( memory_layout == ( unsigned char ) JCKY_CONTIGUOUS_LAYOUT_ID ) { const unsigned long int container_len = meta -> nns [ JCKY_NN_BASE ] . container_len ; unsigned long int elements_per_request = container_len ; if ( meta -> num_blocks ) { if ( container_len % meta -> num_blocks == 0 ) { elements_per_request = container_len / meta -> num_blocks ; } else { elements_per_request = ( container_len / meta -> num_blocks ) + 1 ; } } else if ( meta -> block_size ) { elements_per_request = meta -> block_size / sizeof ( nn_type ) ; } manager -> elements_per_request = ( int ) ( ( elements_per_request > INT_MAX ) ? INT_MAX : elements_per_request ) ; manager -> requests_per_transaction = ( container_len % manager -> elements_per_request == 0 ) ? ( container_len / manager -> elements_per_request ) : ( container_len / manager -> elements_per_request ) + 1 ; manager -> elements_in_last_request = ( int ) ( container_len - ( manager -> elements_per_request * ( manager -> requests_per_transaction - 1 ) ) ) ; nn_number_of_requests *= manager -> requests_per_transaction ; } manager -> neural_net = create_request_manager ( nn_number_of_requests ) ; manager -> sequence = create_request_manager ( child_procs_or_one ) ; if ( cli -> verbose && manager -> master ) printf ( " \n \n " ) ; manager -> training_samples = create_sample_manager ( training_samples , meta -> batch_size , manager , TRAINING_DATA , cli , err ) ; manager -> testing_samples = create_sample_manager ( testing_samples , meta -> batch_size , manager , TESTING_DATA , cli , err ) ; manager -> send_nn_async_func = JCKY_SEND_NN_ASYNC_FUNCS [ memory_layout ] ; manager -> recv_nn_async_func = JCKY_RECV_NN_ASYNC_FUNCS [ memory_layout ] ; }
TODO:
 Make sure types are correct for world size and rank
 Use destructor for this
 Use a data manager
TODO : Make sure types are correct for world size and rank Use destructor for this Use a data manager
// printf("Elements per request: %u\n", manager->elements_per_request); // printf("Requests per transaction: %u\n", manager->requests_per_transaction); // printf("Elements in last request: %u\n", manager->elements_in_last_request); // printf("Number of requests: %u\n", nn_number_of_requests);