# Copyright 2021 - Barcelona Supercomputing Center
# Author: Rodrigo Martín Posada
# MIT License

def def_local_partition(nlon, nlat, npes, mype):
    il_extentx = nlon
    il_extenty = nlat//npes
    if (mype == npes-1):
        il_extenty = nlat - nlat//npes * mype
    il_size = il_extentx * il_extenty
    il_offsetx = 0
    il_offsety = nlat//npes * mype
    il_offset = nlon * il_offsety
    return il_extentx, il_extenty, il_size, il_offsetx, il_offsety, il_offset

def def_paral(decomp, il_offset, il_size, il_extentx, il_extenty, nlon):
    if decomp == 'DECOMP_APPLE':
        return [1, il_offset, il_size]
    elif decomp == 'DECOMP_BOX':
        return [2, il_offset, il_extentx, il_extenty, nlon]
    else:
        raise Exception(f'Invalid CPPKEYDECOMP in {__file__}: {decomp}')
